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
 Transact-SQL (2005)
 reg.altering sp n renaming table

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2009-11-30 : 00:07:50
hi i have two queries here.

1. i need to search for a table by its name first in a database,if it exists i need to rename it.

2. after performing step 1, i need to alter sp(i.e if it is using table name before renaming it,i need to place name after rename in sp).

what are the ways to acheive above task?

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-11-30 : 00:36:40
try with these statments
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE Table_Name = 'tablename'

SELECT DISTINCT OBJECT_NAME(id) FROM SYS.SYSCOMMENTS WHERE TEXT LIKE '%tablename%'

EXEC SP_DEPENDS 'tablename'

EXEC SP_RENAME 'tablename','newtablename'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 01:33:22
Best option is to make use Generate SQL Script option and rename the name by find and replace method

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -