Copying Rows from another Table using SQL

Posted by Syedshakeer under Sql Server category on | Views : 8189
Copying Rows from another Table:
You can use the Insert Statement to add rows to a table where the values are derived from existing tables.In place of the values clause,you can use the subquery.

Insert into table [ column (,column)] subquery;

In the Syntax:
table is the tablename
column is the name of the column in the table to populate
subquery is the subquery that returns rows into the table

The nimber of columns and their datatypes in the column list of the INSERT clause must match the number of values and their data types in the seubquery.To create a copy of the rows of a table,use

Select * in the subquery.

Insert into copy_emp(id,name,salary)
Select * from employees;

1.Donot use the VALUES clause.
2.Match the number of columns in the INSERT clause to those in the Subquery.

Comments or Responses

Login to post response