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)
 Create table with the same structure

Author  Topic 

alejo46
Posting Yak Master

157 Posts

Posted - 2010-08-03 : 13:20:08
Good afternoon:
i've got a table name table201007 with n records, right?
then i need to create an empty table called table201008 with the same structure, the same indexes, ans so on.

i know in SSMS there is an option to create a table with code included, but the question is, it creates the table with the same structure, indexes and so on?

or i know that the command select into is used but duplicates the table?


i'll appreciate your help

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-03 : 13:59:55
The SSMS generate script wizard allows you to select all of the options. What you'll want is constraints, indexes, and triggers.

SELECT INTO only gives you the base DDL of the table and not the other objects.

Instead of creating a new table for every month, you should instead consider storing all of the data into one properly normalized table and then partitioning it by month.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2010-08-04 : 09:56:18
Normalize my table? Are you insane?



http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -