MSSQL%20Interview%20Questions%20and%20Answers
Question: How to create new tables with "SELECT ... INTO" statements in MS SQL Server?Answer: Let's say you have a table with many data rows, now you want to create a backup copy of this table of all rows or a subset of them, you can use the "SELECT ... INTO" statement. The tutorial script below gives you a good example:INSERT INTO wb VALUES (1, 'Learn SQL', 'Visit www.Withoutbook.com','2006-05-01') GO SELECT * INTO wbBackup FROM wb GO (1 rows affected) SELECT * FROM wbBackup GO id subject description create_date 1 Learn SQL Visit www.Withoutbook.com 2008-05-01 sp_columns wbBackup GO TABLE_OWNER TABLE_NAME COLUMN_TABLE TYPE_NAME ... dbo wbBackup id int ... dbo wbBackup subject varchar ... dbo wbBackup description varchar ... dbo wbBackup create_date datetime ... As you can see, the "SELECT ... INTO" statement created a table called "wbBackup" using the same column definitions as the "wb" table and copied all data rows into "wbBackup". |
Is it helpful?
Yes
No
Most helpful rated by users:
- What is Microsoft SQL Server?
- What is the simplest way to create a new database in MS SQL Server?
- How to delete a database in MS SQL Server?
- How to download and install Microsoft .NET Framework Version 2.0?
- How To Get a List of Columns using the "sp_help" Stored Procedure in MS SQL Server?