Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Copy table Structure

Author  Topic 

SQLSeeker
Starting Member

15 Posts

Posted - 2009-10-09 : 09:36:02
Hi friends,
I want to create a stored procedure to copy all tables with different names within same database. I already tried "Select * into <Desttblname> from <Sourcetblname> where 1=2" this option. This query copied only field information, all other primary and foreign key related information not copied.

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-09 : 09:49:19
quote:
Originally posted by SQLSeeker

Hi friends,
I want to create a stored procedure to copy all tables with different names within same database. I already tried "Select * into <Desttblname> from <Sourcetblname> where 1=2" this option. This query copied only field information, all other primary and foreign key related information not copied.

Thanks


You should take script of the tables using Genreate Script option and change the table names accordingly

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-10-09 : 10:20:31
Hi

Right Click Database -->Tasks--Generate Scripts--->select Database





-------------------------
R...
Go to Top of Page

SQLSeeker
Starting Member

15 Posts

Posted - 2009-10-14 : 03:03:02
quote:
Originally posted by madhivanan

quote:
Originally posted by SQLSeeker

Hi friends,
I want to create a stored procedure to copy all tables with different names within same database. I already tried "Select * into <Desttblname> from <Sourcetblname> where 1=2" this option. This query copied only field information, all other primary and foreign key related information not copied.

Thanks


You should take script of the tables using Genreate Script option and change the table names accordingly

Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

SQLSeeker
Starting Member

15 Posts

Posted - 2009-10-14 : 03:10:09
Hi Madhivanan,
Thanks for your reply,Actually I want to copy all tables from same database with different names so that with the help of script generator i need to replace every entry of old table with new table name. I think it is not proper way because I want to do this as one activity.Any other way to achieve this.
Go to Top of Page
   

- Advertisement -