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 2005 Forums
 SQL Server Administration (2005)
 Recreating indexes from one table onto another

Author  Topic 

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-01 : 12:04:54
Hi all,

Any idea how to do this? I copied data from a table and inserted in into another with the same column names.

Cheers,

Jim

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-01 : 12:07:09
That is no REcreate.
Skript out the indexes from the source table and execute it adapted on the new table.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-01 : 12:20:10
quote:
Originally posted by webfred

That is no REcreate.
Skript out the indexes from the source table and execute it adapted on the new table.


No, you're never too old to Yak'n'Roll if you're too young to die.



Using 'Alter Table'?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-01 : 12:29:44
Yes.

What I would do:
Go to the object explorer
Expand databases
Expand your table
Expand indexes
Right click the index and choose create to a new query window
This will generate the ALTER statement for you
Change the tablename
execute it in the database which holds the new table

That should work.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-01 : 13:33:04
Well you'll need ALTER TABLE for the PK, but you'll need CREATE INDEX for the other stuff. SSMS will generate the proper script, so you should see ALTER/CREATE if you've got more than just the PK on the table.

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

Subscribe to my blog
Go to Top of Page

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-01 : 13:48:30
quote:
Originally posted by webfred

Yes.

What I would do:
Go to the object explorer
Expand databases
Expand your table
Expand indexes
Right click the index and choose create to a new query window
This will generate the ALTER statement for you
Change the tablename
execute it in the database which holds the new table

That should work.


No, you're never too old to Yak'n'Roll if you're too young to die.



That indeed works, danke! Rather laborious process on a Friday night, the Clustered Index build is taking an age at a time when I ought to be in the pub...

:)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-03 : 13:32:59
when I ought to be in the pub...
Take a netbook with you


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-04 : 01:47:03
quote:
Originally posted by Jim Beam

quote:
Originally posted by webfred

Yes.

What I would do:
Go to the object explorer
Expand databases
Expand your table
Expand indexes
Right click the index and choose create to a new query window
This will generate the ALTER statement for you
Change the tablename
execute it in the database which holds the new table

That should work.


No, you're never too old to Yak'n'Roll if you're too young to die.



That indeed works, danke! Rather laborious process on a Friday night, the Clustered Index build is taking an age at a time when I ought to be in the pub...

:)



Well you can set the option SORT_IN_TEMPDB=ON in the index creation script.It will give the necessary testosterone boost for the index creation

http://msdn.microsoft.com/en-us/library/ms188281.aspx

Edit:Corrected the hyperlink

PBUH

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-04 : 04:23:24
quote:
Originally posted by Sachin.Nand

quote:
Originally posted by Jim Beam

quote:
Originally posted by webfred

Yes.

What I would do:
Go to the object explorer
Expand databases
Expand your table
Expand indexes
Right click the index and choose create to a new query window
This will generate the ALTER statement for you
Change the tablename
execute it in the database which holds the new table

That should work.


No, you're never too old to Yak'n'Roll if you're too young to die.



That indeed works, danke! Rather laborious process on a Friday night, the Clustered Index build is taking an age at a time when I ought to be in the pub...

:)



Well you can set the option SORT_IN_TEMPDB=ON in the index creation script.It will give the necessary testosterone boost for the index creation

http://msdn.microsoft.com/en-us/library/ms18828(SQL.100).aspx

PBUH




LOL. Nice one Sachin!

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-04 : 11:07:59
Only use SORT_IN_TEMPB if your tempdb database is optimized.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -