top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to copy a table from one to another table in sql?

+1 vote
426 views

How to copy a table from one to another table in sql?

posted Jul 17, 2014 by Sanjay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Here is the updated script of copy a table from one to another table in sql :-
-- Method 1 : INSERT INTO SELECT

USE AdventureWorks2012 GO

----Create TestTable

CREATE TABLE TestTable (FirstName VARCHAR(100), LastName VARCHAR(100))

----INSERT INTO TestTable using SELECT

INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Person
WHERE EmailPromotion = 2

----Verify that Data in TestTable

SELECT FirstName, LastName
FROM TestTable

----Clean Up Database

DROP TABLE TestTable GO

---------------------------------------------------------

-- Method 2 : SELECT INTO

USE AdventureWorks2012 GO

----Create new table and insert into table using SELECT INSERT

SELECT FirstName, LastName
INTO TestTable
FROM Person.Person
WHERE EmailPromotion = 2

----Verify that Data in TestTable

SELECT FirstName, LastName
FROM TestTable

----Clean Up Database

DROP TABLE TestTable GO
answer Jul 20, 2014 by Vrije Mani Upadhyay
Similar Questions
+3 votes

This is the Sales_Import table, where the account number field needs to be updated:
LeadID AccountNumber

147 ********** 
150 ********** 
185 7006100100007267039

And this is the RetrieveAccountNumber table, where I need to update from:
LeadID AccountNumber

147 7006100100007266957 
150 7006100100007267039 
+2 votes

I want to update data from one table to another table with year condition.
(OR)
To Update one table based on another table using INNER JOIN

0 votes

I installed informatica PC8.6 on Windows XP and SQL Server 2008 R2 on another machine. How can I access this database from informatica pc.8.6. and is it possible to access?

...