August 29, 2018
Populating Tables: A Hidden Art
- Using the INSERT Statement
- Using the INSERT DEFAULT VALUES Statement
- Using the INSERT VALUES Statement
- USING the INSERT SELECT Statement
- Leveraging Defaults
- Using the INSERT EXEC Statement
- Using the SELECT INTO Statement
- The Bulk Copy Program-bcp
- USING THE BULK INSERT Statement
- BATCHSIZE
- CHECK_CONSTRAINTS
- CODEPAGE
- DATAFILETYPE
- FIELDTERMINATOR
- FIRETRIGGERS
- FIRSTROW
- FORMATFILE
- KEEPIDENTITY
- KEEPNULLS
- KILOBYTES_PER_BATCH
- LAST_ROW
- MAXERRORS
- ORDER
- ROWS_PER_BATCH
- ROWTERMINATOR
- TABLOCK
- Loading Data
- Normalizing Data
- Generating Test Data
After creating a table in a database, there’s four main ways of filling them with data: 1.) using the INSERT statement, 2.) Using the BULK INSERT statement, 3.) Using the bulk copy utility (bcp) – the progenitor of the BULK INSERT statement, and 4.) using Data Transformation Services (DTS), which offeres a broad range of ways to load a table.
Using the INSERT statement:
The INSERT statement can typicall be broken down into INSERT VALUES, INSERT SELECT, and INSERT EXEC. Here is the syntax for the INSERT Statement:
INSERT [INTO]
{
table_name WITH [table_hint_limited] […n])
| view_name
| rowset_function_limited
}
{[(column_list)]
{VALUES ({DEFAULT
| NULL
| expression
} [,…n]
)
| derived_table
| execute_statement
}
}
| DEFAULT VALUES
[table_hint_limited]::=
{INDEX(index_val [,…n])
| FASTFIRSTROW
| HOLDLOCK
| PAGLOCK
| READCOMMITED
| REPEATABLEREAD
| ROWLOCK
| SERIALIZABLE
| TABLOCK
| TABLOCKX
| UPDLOCK
}