MSSQL Server 2005
I’m currently working with MSSQL Server 2005 and why does Microsoft have to make everything difficult? With MySQL, a multiple insert is as simple as INSERT INTO table (columns) VALUES (array of values), (another array of values), … (last array of values). This way works in MS SQL 2008, but that’s another expense.
My current assignment in the office is to export and import MS Access data into a completely different schema in MSS. I will pose a problem at the end of this entry and if someone has a solution, I would be grateful to you.
Multiple insert in MSSQL 2005 Thanks to Pinal Dave for this
USE database_name GO INSERT INTO table_name (column1, column2, ... columnN) SELECT 'value1a', 'value2a', ... 'valueNa' UNION ALL SELECT 'value1b', 'value2b', ... 'valueNb' ... UNION ALL SELECT 'value1n', value2n', ... 'valueNn'
Problem: How would I do a SELECT…INSERT in the middle of an insert because one or more columns are foreign keys. That way I don’t have to verify my data before inserting. Have the machine do it for me. For instance:
USE database_name GO INSERT INTO table_name (column1, column2, ... columnN) SELECT 'value1a', [SELECT...INSERT], ... 'valueNa' UNION ALL SELECT 'value1b', [SELECT...INSERT], ... 'valueNb' ... UNION ALL SELECT 'value1n', [SELECT...INSERT], ... 'valueNn'
Add comment July 23rd, 2008
