C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...









How to insert values from existing table into new table with same table structure?


Posted Date: 27 Jun 2008    Resource Type: Code Snippets    Category: SQL

Posted By: Satyanarayan SushilKumar Bajoria       Member Level: Gold
Rating:     Points: 1





Insert into new_table
Select * from existing_table

Remember Table structure should be same.




Responses

Author: Anjali Sharma    30 Jun 2008Member Level: Gold   Points : 0
hi
ur code is not wrking


Author: Satyanarayan SushilKumar Bajoria    30 Jun 2008Member Level: Gold   Points : 1
Hi Angali,

May i know the error what u r getting.


Author: Payal Mani Jain    01 Jul 2008Member Level: Gold   Points : 1
try using the columns names too like

Insert into new_table(column1,column2)
Select column1,column2 from existing_table



Author: Abhijeet Kumar    03 Jul 2008Member Level: Gold   Points : 1
Try something like:

INSERT INTO Names_New (name, state)
SELECT name, state FROM Names_Old


Author: UltimateRengan    04 Jul 2008Member Level: Diamond   Points : 2
hi,
Your Code is not working.
This is the correct format for insert values from existing table into new table with same table structure

select * into NewTableName from ExistingTableName
EX:
select * into GG from b

i hope this may help u


Author: UltimateRengan    04 Jul 2008Member Level: Diamond   Points : 2
this error will occur:

Msg 208, Level 16, State 1, Line 1
Invalid object name 'c'.





Author: UltimateRengan    04 Jul 2008Member Level: Diamond   Points : 2
hi,



Author: Satyanarayan SushilKumar Bajoria    04 Jul 2008Member Level: Gold   Points : 2
Hi UltimateRengan,

first understand question clearly then reply.I know u r very smart.

I try my code is working.

There is one table already exist say table1 with the same structure say table2.

Whatever answer u r posted is also right but it will create the table and i m talking about if table is already exist.


Author: Satyanarayan SushilKumar Bajoria    04 Jul 2008Member Level: Gold   Points : 2
Hi UltimateRengan,

first understand question clearly then reply.I know u r very smart.

I try my code is working.

There is one table already exist say table1 with the same structure say table2.

Whatever answer u r posted is also right but it will create the table and i m talking about if table is already exist.


Author: Satyanarayan SushilKumar Bajoria    04 Jul 2008Member Level: Gold   Points : 2
Hi UltimateRengan,

You follow the steps that i m mentioning below.

Select * into table1
from table2
where 1=2

It will create the table1 with the same structure as that of table2.

Now try my code given below.

Insert into table1
Select * from table2

Now tell whether it will give error or not..


Author: Pravin    07 Jul 2008Member Level: Bronze   Points : 0
Select * into New_Table FROM Old_Table


Author: Jaya Kumar    10 Jul 2008Member Level: Gold   Points : 0
SELECT *
FROM Table1
INTO Table2


Author: palla    28 Aug 2008Member Level: Bronze   Points : 2
hi
for using this insert first we have to create the table.it wont copies the same structure as source table.

insert into destinationtable(already existed table)(columlist)
select * or (columlist)
from source table
where

try it .it can work for permananttables,temporarytablesand for table variables also.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: INSERT and UPDATE using Triggers in SQL Server
Previous Resource: caluclate age in years
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use