0

I have a stored procedure that creates a table, inserts data into the table, and now I need to alter the table to

1) Rename an existing field to a new name
2) Add a new field with the same name as the field we just renamed

I tried this syntax however my SSMS freezes anytime I execute and I have to ctrl+alt+del to close....I feel that is unrelated to the syntax, but wanted to ask

    Create Table TMI (empName varchar(500), userID varchar(100), TV float)

CREATE NONCLUSTERED INDEX eNIndex 
ON TMI (empName ASC)

dbo.sp_RENAME '[dbo].TMI.TV' , 'OrigTV', 'COLUMN'

ALTER TABLE [dbo].TMI
ADD TV float;
2
  • In general, try using the latest version of SSMS (17.3 as of writing) and you'll find you get far fewer crashes and freezing. Commented Oct 10, 2017 at 17:52
  • @LowlyDBA - thanks for the tip! I will upgrade to a newer version of SSMS Commented Oct 10, 2017 at 18:19

1 Answer 1

3

Couple of things...

The sp_rename procedure is in the sys schema, not dbo.

Second, if you execute a stored procedure in a batch, then you must use the EXEC keyword.

Try changing your code to this:

CREATE Table TMI (empName varchar(500), userID varchar(100), TV float)

CREATE NONCLUSTERED INDEX eNIndex 
ON TMI (empName ASC)

EXEC sys.sp_rename '[dbo].TMI.TV' , 'OrigTV', 'COLUMN'

ALTER TABLE [dbo].TMI
ADD TV float;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.