Importing Data into SQL Server – Using the INSERT statement

Sometimes, the easiest and quickest way to get data into SQL Server is to simply use an INSERT statement.  Here is what the INSERT statement looks like in Books Online(BOL) [ WITH <common_table_expression> [ ,…n ] ] INSERT     [ TOP ( expression ) [ PERCENT ] ]     [ INTO ]     { <object> | rowset_function_limited       [ WITH ( <Table_Hint_Limited> [ …n ] ) ]     } {     [ ( column_list ) ]     [ <OUTPUT Clause> ]     { VALUES ( ( { DEFAULT | NULL | expression } [ ,…n ] ) [ ,…n ] )     | derived_table     | execute_statement | <dml_table_source>     | DEFAULT VALUES … Continue reading Importing Data into SQL Server – Using the INSERT statement

Importing Data into SQL Server – Using the Import Export Wizard

Today begins the series on importing data into SQL Server 2005/2008 using the various built in tools. With SQL Server, there are several ways of getting your data from one place to another. Today, we will focus on using the wizard from SQL Server Management Studio. Before we begin, I am using a simple database called testdb. I am also using a country code file found at http://www.andrewpatton.com/countrylist.html. The file contains the 2 and 3 character ISO 3166 Country Code abbreviations, which we will use in our sample. The CSV file as seen in Excel 2007 Here is the script … Continue reading Importing Data into SQL Server – Using the Import Export Wizard

Storing Computed Columns in SQL Server

From time to time you will run into a case where you need to store computed columns in your SQL Server tables. Examples of computed columns include taxes on a sale or business days between several dates. Setting  up computed columns in SQL Server 2008 is fairly simple. You simply give the column a name and then specify your calculation instead of giving a datatype. You could even use a case statement instead of functions and calculations. Here is an example of a table that calculates days between 2 dates. CREATE TABLE dbo.DateDiffTable ( RowID int NOT NULL IDENTITY (1, … Continue reading Storing Computed Columns in SQL Server