The document outlines two cases for copying data from an existing table to a new table in SQL. In Case 1, a new table is created with the same structure and records as the existing table, or only certain columns can be copied. In Case 2, if the new table structure already exists, data can be inserted into it from the existing table, either by copying all records or specific columns.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views1 page
Lec 38 SQL Practice
The document outlines two cases for copying data from an existing table to a new table in SQL. In Case 1, a new table is created with the same structure and records as the existing table, or only certain columns can be copied. In Case 2, if the new table structure already exists, data can be inserted into it from the existing table, either by copying all records or specific columns.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
--Copying Data From existing table to the New table
--Case 1 : The New table simply doesn't exist
--Case 2: The New table structure/New Table exists
--CASE 1 : select * from dbo.Sales
--All columns were copied from existing table
--This statement will result in the creation of New_Table_1 which will be having structure & records both --same as that of dbo.sales table select * into New_Table_1 from dbo.Sales
-------------------Certain Columns to be copied
drop table New_Table_1
select productid,quantity into new_table_1 from dbo.Sales
select * from new_table_1
--CASE 2 : New table structure/table already exists
select top 0 * into new_table_2 from dbo.Sales --****************************
select * from new_table_2
insert into new_table_2 select * from dbo.Sales
------Copying Certain Columns
select * into new_table_3 from dbo.Sales where 1=0 ---****************************
select * from new_table_3
insert into new_table_3 (ProductID,SaleDate) select productid,saledate from