Saturday, July 29, 2017

What is two digit year cutoff in SQL Server?

Remember the millenium bug fiasco. It happenned in Year 2000.
This is what chronicled in Wikipedia:

"The Year 2000 problem is also known as the Y2K problem, the Millennium bug, the Y2K bug, or Y2K. Problems resulted because people, including programmers, reduced the four-digit year to two digits. This made the year 2000 indistinguishable from 1900"

Now we have a better interpretation for people using two digit years as far as SQL Server is concerned.

The default time span for SQL Server is 1950-2049.

Two-digit year 49 is 2049, but two digit year 50 is back to 1950.

Probably you will start seeing it in your credit cards (may be?)

You may configure it in SQL Server 2017 using,

Exec Sp_Configure 'two digit year cutoff', 2038

In SQL Server 2012 Express it is enabled by default:



Read more here:
https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-two-digit-year-cutoff-server-configuration-option

What is mssql-scripter?

In your SSMS on your computer you can use the Generate Scripts drop-down
menu to create scripts for database objects as shown here for Northwind database on SQL Server 2016 SP1.

However, the above is for SQL Server on Windows Platform. However, mssql-scripter tool provide the same functionality as Generate Scripts wizard on SQL Servers on Linux and macOS. Of course mssql-scripter would work on Windows as well.

Using mssql-scripter based on Python you can generate T-SQL scripts for objects on SQL Servers, Azure SQL database and Azure SQL Data Warehouse.

The generated script is saved to a .sql file or, on Linux can be piped to standard Unix utilities (sed, awk and grep ). The scripts can be checked into source control systems as well.

The source code for mssq-scripter is found here:
https://github.com/Microsoft/sql-xplat-cli

Thursday, July 27, 2017

Usage Modulo: How many hours and minutes are there in so many minutes?

x%y is defined as the remainder of the division x/y. You can use modulo to find the minutes and hours in so many minutes.

Let us say we have a cconversion exercise to convert 123490 minutes into minutes and hours.
By long hand we would do this:

123490/60 and find the remainder
We get 2058.1666666667 with 0.1666666667 hours converts to 10
That is 2058 hours and 10 minutes.

We can do the same using modulo as shown.


OR

You can use a much shorter code as shown here: (note input data has changed to 1234901)


Sunday, July 23, 2017

How does the string function STRING_SPLIT() work?

When compared to an earlier version, SQL Server 2016 has two new string functions shown in the next image.



String2016.png

The syntax for the new function:
STRING_SPLIT ( string , separator )

Let us take this string:

'quote, substring, toLowerCase, toUpperCase, charAt,
      charCodeAt, indexOf, lastIndexOf'

Now write the following code in the query pane of SQL Server 2016 as shown. When the query is evaluated we see that the string is split at the comma (,) as shown. The white spaces are preserved.




How to test a comparison operator in an SQL Query?

Let us say we want to know if a variable x is greater or less than another variable y. How do we write a query to test it?

One way to do this is as follows:

declare @x int
set @x=5
declare @y int
set @y=10
    IF @x < @y
 print 1
    ELSE
 print 0

Saturday, July 22, 2017

Why did YouTube disappear from my Samsung Smart TV?

This happenned on our Samsung Model UN46F7500AF Smart TV purchased in 2013 but the Model began selling in 2012. Speaking to the Samsung support team in USA gives me the feeling that YouTube created a new platform and that the older TV (Prior to 2012) does not support the new YouTube platform.

I will have to pursue this matter with YouTube site for confirmation.

In Summary, the reason YouTube disappeared is not because of Samsung, but because of YouTube's changes.

Monday, July 17, 2017

What is a Single Page Application?

It is exactly what it says. Single Page Applications (SPAs) are web applications with a single web page that uses AJAX for its dynamic interactions. As page refresh is on the client side the SPAs can have downside of performance degradation if they are not properly designed and SEO optimized.

There are many JavaScript frameworks to write SPAs. There are lots of JavaScript frameworks that you can use to build SPAs. Lots of them are Open Source. Here are some:

WinJS
Angular
React
Ember
Aurelia
Dojo
Vue.js
Cycle.js
Backbone
Dojo


I hear a lot about Angular and Aurelia, perhaps more people are using them.
Intel XDK had both Angular and Backbone templates, but they are not supporting them anymore.

AngularJS is in Version 2.

I have a large number of posts on Intel XDK here.

Sunday, July 16, 2017

How do you restore a database from its backup?

A backup of Northwind database was obtained from the Codeplex site and was saved to one of the folders on a Dell computer with Windows 10 OS. The computer also has SQL Server Management Studio (v 17.1). You should be able to restore using the SQL Server Management Studio installed when you installed the SQL Server 2012 Database engine.

Follow these steps to restore the Northwind database to an instance of SQL Server 2012 (x86) installed on the same computer.

Step 1. Start SQL Server Management Studio v17.1 (Run as administrator)

The SSMS is version 17.1 and Hodentek9\PCATT is a SQL Server 2012 Express

Step 2. Right click the Databases node highlighted in the PCATT isntnace as shown.




RestoreDB_01

Step 3: Click Restore Database...

Restore Database window is displayed as shown.


RestoreDB_02

Step 4: The Default Source is Database and it is greyed out as shown. Chnage it to Device. The Restore Database gets changed as shown.


RestoreDB_03

Step 5: Click the ellipsis button along 'Device' in the above image.

Select backup devices window shows on top of Restore Database window as shown.


RestoreDB_04

Step 6: Click Add button in Select backup devices window.
Locate Backup File window gets displayed as shown.


RestoreDB_05

Usually the 'backup files with extension .bak' are found in the following directory in the case of x32 bit SQL Server.
C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.PCATT\MSSQL\Backup

However, for this exercise it is stored in a different location.

Step 7: Now browse to that location and highlight the Northwind.bak (A backup file which came from a Microsoft site) as shown.


RestoreDB_06

Step 8: Click OK. The file path is entered in the Select backup devices window as shown.


RestoreDB_07.png

Step 9: Click OK
You are returned to the Restore Database - Northwind as shown.


RestoreDB_08.png

Step 10: Click OK in the above.

Microsoft SQL Server Managment Studio message reports that the database
'Northwind' restored successfully.


RestoreDB_09.png

Step 11: Click OK to the message. Verify that Northwind database is in the SQL Server 2012 instance Hodentek9\PCATT


RestoreDB_10.png


Bye




Thursday, July 13, 2017

What is Dynamic Data Masking?

The title is quite revealing, is it not?

Dynamic Data Masking which is available in SQL Server 2016 allows you provide another level of security to your data, by masking data that you do not want unauthorized (by policies) users to peek into. Data in the database itself is unchanged. SQL Server 2016 has other security features besides dynamic data masking.

This is a nice feature that you should implement if are dealing with sensitive information (Credit card numbers, Social Security Numbers, etc).

Here is an image of credit card numbers being masked



Credit card masking imaged source: http://www.gsapps.com/images/masking2.gif

Read here about masking using JavaScript:

https://stackoverflow.com/questions/25367230/masking-a-social-security-number-input

Do you need special permission to create a table with a dynamic data mask?

No, you do not. Of course you need standard permissions like Create table, Alter on schema permissions.

The Alter Any Mask permission and Alter permission on  a Table are needed, though.

Read more about Dynamic Data Masking here:
https://docs.microsoft.com/en-us/sql/relational-databases/security/dynamic-data-masking

Wednesday, July 12, 2017

How to handle this Power Shell error, "Set-Location: a Positional parameter..."?

Power Shell does not like white spaces. While it may like or .  I got stumped for while as I started getting this exception.



The trick to do this changing directory is to use double quotes around words with white spaces as shown here.


I have Power Shell 5.0 on my Windows 10 Pro OS.

What is Microsoft Graph?

Microsoft SQL Server is for accessing data and Microsoft Graph is to access the myriad of things that are not really part of the database. The things that spring to the mind are things like, emails; your devices; the teams you work with; calendars; files; messages, peoples etc..

Also read this post on Graph databases:
http://hodentek.blogspot.com/2013/12/what-is-neo4j.html

A quick look at this image shows how Microsoft Graph is positioned.



Well, what is it Microsoft Graph good for?

Believe me, you indeed have a great deal of use for it. Allow me to quote Microsoft:

'Looks at your next meeting and helps you prepare for it by providing profile information for attendees, including their job titles and who they work with, as well as information on the latest documents and projects they're working on (pro-active, do diligence).

Scans your calendar, and suggests the best times for the next team meeting.

Fetches the latest sales projection chart from an Excel file in your OneDrive and lets you update the forecast in real time, all from your phone.

Subscribes to changes in your calendar, sends you an alert when you’re spending too much time in meetings, and provides recommendations for the ones you could miss or delegate based on how relevant the attendees are to you.

Helps you sort out personal and work information on your phone; for example, by categorizing pictures that should go to your personal OneDrive and business receipts that should go to your OneDrive for Business.
'
Behind Microsoft Graph is the Microsoft Graph API; a RESTful web api that enables you to access Microsoft Cloud serivce resources.

Come back to this blog again for more on Microsoft Graph.

Thursday, July 6, 2017

Can you install SQL Server Express (x86) on Windows 10 (x64 bit)?

The short answer is YES.

A x32 bit SQL Server Express Advanced and a x64 bit SQL Server 2016 SP1 are both installed on a Dell Inspiron laptop.

Here are the responses to the command:

SELECT @@version in a query launched by both of these versions:

(No column name)
Microsoft SQL Server 2012 - 11.0.2100.60 (Intel X86)   Feb 10 2012 19:13:17   Copyright (c) Microsoft Corporation  Express Edition on Windows NT 6.2 (Build 9200: ) (WOW64)

(No column name)
Microsoft SQL Server 2016 (SP1-GDR) (KB3210089) - 13.0.4202.2 (X64)   Dec 13 2016 05:22:44   Copyright (c) Microsoft Corporation  Developer Edition (64-bit) on Windows 10 Pro 6.3 (Build 15063: )

They can co-exist as shown: