Microsoft SQL Server and SQL Server Management Studio

A category to select articles regarding Microsoft SQL Server and SQL Server Management Studio 2012.

Importing text files into tables in SQL Server database schemas can be done using different methods.

One method using SQL Server specific SQL is shown below.

SQL Script

If you want to use tab delimited source files you can type in the delimiter into FIELDDELIMITER using the tabulator key in SQL Server Management Studio.

BULK
INSERT CSVTest
FROM 'c:\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

 

In order to divide two integer type fields in SQL Server you will have to apply a type cast before applying the mathematical operation.

Else you will receive zero (0) as a result whenever one of the numbers is not null, which is obviously not what we want.

In order to change a connection for a single query in SQL Server Management Studio 2012 right click into the query text and select Connection > Change Connection ... from the context menu.

This will bring up a dialog in which you are able to change connection settings like the database server or the standard target database.

If you want to change details of the connection like selecting a database schema to connect to, expand the options in the bottom right of the connection dialog.

In the connection tab "Connection Properties" select the option "Connect to database" to show the target database you want and hit connect.