Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Thursday, 30 June 2016

How to copy table structure and data from one table to another table in same database or different in MSSql Server

No comments :
Here is the explanation of copy database table data and structure from one table to another in sql server 2008/2008 R2/2010/2012.

Procedure:
We have list of data in this Country table.
select * from Country

Method 1:
If you want to copy this entire data with structure (field names and datatypes) to another table with the different name using below queries.
Syntax:
Select * into newtablename from oldtablename

Ex: Select * into CountryNames from Country

You want to copy only specific data into other table using below format.

Syntax:
Select  col1,col2 into newtablename from oldtablename

Ex: Select CountryId,CountryName into CountryNames from Country
Method 2:
Syntax:
Insert into newtablename Select * from oldtablename
Ex: Insert into CountryNames Select * from Country

For particular columns

Insert into newtablename (col1,col2,col3) Select col1,col2,col3 from oldtablename

No comments :

Post a Comment