Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
QuietRiot
Yak Posting Veteran
67 Posts |
Posted - 2008-01-29 : 16:21:35
|
2 simple questionsif im doing an insert and want to add multiple rows do i just add multiple 'values' like below with just 1 insert Into:INSERT INTO table_name (column1, column2,...)VALUES ('value1', 'value2',....)VALUES ('value1', 'value2',....)VALUES ('value1', 'value2',....)2nd question:will '' give me a null value? like so:VALUES ('', 'Value2',....) |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-01-29 : 16:45:11
|
1. No. The easiest way to do this is to UNION each set of columns like so:INSERT INTO table_name (column1, column2,...)SELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',....2. No. '' <> NULLThe following will insert a NULL value into column2 of your table:INSERT INTO table_name (column1, column2)VALUES ( 'value1', NULL )And so will this:INSERT INTO table_name (column1)VALUES ( 'value1' ) |
 |
|
QuietRiot
Yak Posting Veteran
67 Posts |
Posted - 2008-01-29 : 16:50:06
|
you mean you have to use SELECT and UNION all for each new row you're adding to the table?quote: No. The easiest way to do this is to UNION each set of columns like so:INSERT INTO table_name (column1, column2,...)SELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',....
|
 |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-01-29 : 16:54:29
|
quote: Originally posted by QuietRiot you mean you have to use SELECT and UNION all for each new row you're adding to the table?quote: No. The easiest way to do this is to UNION each set of columns like so:INSERT INTO table_name (column1, column2,...)SELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',.... UNION ALLSELECT 'value1', 'value2',....
I write code, damnit, not sentences! Yes, thats what I meant. Thanks. |
 |
|
|
|
|
|
|