Thursday, March 29, 2012

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
ThanksHi
On Jun 11, 5:19 pm, Omar Abid <omar.abid2...@.gmail.com> wrote:
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
If you just want to create copy the data then you could use
SELECT *
INTO #temptable
FROM Mytable
Which will create a new table with the contents of the old table, but
the new table will not have the constraints such as primary or foreign
keys and indexes that the original table had. If you dont want the
table but just the columns use a where clause that will never be
satisfied such as
WHERE 1 = 0
Alternatively you can use SMO see Allen Whites posts in the thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876099&SiteID=1
John

No comments:

Post a Comment