Reputation: 899
Is it possible to copy a table (with definition, constraints, identity) to a new table?
Upvotes: 2
Views: 503
Reputation: 36451
Another possibility:
I just found this old answer on SO.
This script is an example to script the constraints of all tables, but you can easily change it to select only the constraints of "your" table.
So, you could do the following:
Upvotes: 0
Reputation: 36451
It's not the most elegant solution, but you could use a tool like the free Database Publishing Wizard from Microsoft.
It creates an SQL script of the table definition including data and including indexes and stuff. But you would have to alter the script manually to change the table name...
Upvotes: 0
Reputation: 25390
Upvotes: 1
Reputation: 135171
No, not really, you have to script it out, then change the names
you can do this
select * into NewTable
FROM OldTable
WHERE 1 =2 --if you only want the table without data
but it won't copy any constraints
Upvotes: 0