Saturday, February 25, 2012

Creating New tables by copying existing table

Hi,
Is there any easy way of copying the structure of a table within a single
database and creating a new table with a new name. I have an app that the
structure of several new tables is close enough that it would save time if I
could create one and copy and recreate a new one under a new name. Then I
would only have to make the changes that are different.
thanks,
hughVery Easy
Select * into NewTableName from OldTableName where 1= 0
Keep in mind that this is just the table structure no keys, constraints or
indexes are created
http://sqlservercode.blogspot.com/
"Hugh O" wrote:

> Hi,
> Is there any easy way of copying the structure of a table within a single
> database and creating a new table with a new name. I have an app that the
> structure of several new tables is close enough that it would save time if
I
> could create one and copy and recreate a new one under a new name. Then I
> would only have to make the changes that are different.
> thanks,
> hugh
>
>|||Script the CREATE TABLE statement and then edit it. You can do that in Query
Analyzer.
David Portas
SQL Server MVP
--
"Hugh O" <HughLD@.newsgroup.nospam> wrote in message
news:%23kGLB6DzFHA.2008@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is there any easy way of copying the structure of a table within a single
> database and creating a new table with a new name. I have an app that the
> structure of several new tables is close enough that it would save time if
> I could create one and copy and recreate a new one under a new name. Then
> I would only have to make the changes that are different.
> thanks,
> hugh
>|||Hi
You should consider putting your table definitions under version control in
which case you could use the scripting options on Enterpeise Manager or
Query Analyser to create the file to be edited.
John
"Hugh O" <HughLD@.newsgroup.nospam> wrote in message
news:%23kGLB6DzFHA.2008@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is there any easy way of copying the structure of a table within a single
> database and creating a new table with a new name. I have an app that the
> structure of several new tables is close enough that it would save time if
> I could create one and copy and recreate a new one under a new name. Then
> I would only have to make the changes that are different.
> thanks,
> hugh
>|||>> I have an app that the structure of several new tables is close enough th
at it would save time if I could create one and copy and recreate a new one
under a new name. Then I would only have to make the changes that are diffe
rent. <<
Be careful about this. While not a certainity, this is a sign that you
might have split a table on an attributes. For example, someone
recently posted a set of tables where an event had been put into a
temporal table and a separate physical location table and then was
trying to tie them back together to answer queries about the location
and status at a site.|||Thanks SQL, David, John, & Celko
These newsgroups are great. So helpful and shows the diversity and
alternatives so clearly.
hugh
"Hugh O" <HughLD@.newsgroup.nospam> wrote in message
news:%23kGLB6DzFHA.2008@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Is there any easy way of copying the structure of a table within a single
> database and creating a new table with a new name. I have an app that the
> structure of several new tables is close enough that it would save time if
> I could create one and copy and recreate a new one under a new name. Then
> I would only have to make the changes that are different.
> thanks,
> hugh
>

No comments:

Post a Comment