.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Copying Rows from another Table using SQL

Posted By:Syed Shakeer Hussain       Posted Date: February 17, 2009    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  
 

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.

 

 

 

Syntax:

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;

 

Note:

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

 



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend