MS SQL Server: Temporary Tables
Just a way of using temporary tables in Microsoft SQL Server, if you want to duplicate one or more records quickly, you can use commands like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SELECT * INTO #temporary FROM table1 WHERE idfield=1; --create similar table by selecting a record GO UPDATE #temporary SET idfield=2; -- change primary key value -- otherwise, we cannot insert into source table1 GO INSERT INTO table1 SELECT * FROM #temporary; GO |
This is much shorter if you have 50 fields in your source table. Otherwise, you have to specify each field and their data types;