Tuesday, March 20, 2012

Alter table name

Is there a way to alter a table name through query analyser.
I know how to do it through enteprise manager but would like to create a job
or package that runs daily and renames an existing table and creates a new
one.You can use sp_rename, see Books Online...
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:OB1G5zR4EHA.2676@.TK2MSFTNGP12.phx.gbl...
> Is there a way to alter a table name through query analyser.
> I know how to do it through enteprise manager but would like to create a
job
> or package that runs daily and renames an existing table and creates a new
> one.
>|||check out sp_rename in BOL.
--
Andrew J. Kelly SQL MVP
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:OB1G5zR4EHA.2676@.TK2MSFTNGP12.phx.gbl...
> Is there a way to alter a table name through query analyser.
> I know how to do it through enteprise manager but would like to create a
> job or package that runs daily and renames an existing table and creates a
> new one.
>|||You can change object names with sp_rename. A simple example:
EXEC sp_rename 'Table1', 'Table1_Old'
GO
CREATE TABLE Table1
(
MyData int
)
GO
Note that renaming a table will not rename the associated constraints or
triggers. You'll need to rename those object too before recreating.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Grant Merwitz" <grant@.magicalia.com> wrote in message
news:OB1G5zR4EHA.2676@.TK2MSFTNGP12.phx.gbl...
> Is there a way to alter a table name through query analyser.
> I know how to do it through enteprise manager but would like to create a
> job or package that runs daily and renames an existing table and creates a
> new one.
>

No comments:

Post a Comment