TechGuy
TechGuy

Reputation: 4560

Alter table to Change Column Name error

Here I tried to ALTER a table to change column name but an error happens.

Alter table [dbo].[Users] 
CHANGE
username UserName varchar(50),
password PassWord varchar(50),
state State int,
name Name varchar(50),
license License varchar(50),
lansno LansNo varchar(50) ,
curcuit_no CurcuitNo varchar(50) ,
communism Communism varchar(100) ,
Olduid OldUid int ,
Is_hunter Is_Hunter bit ,
free_text [FreeText] text ,
country Country varchar(50) ,
curcuit Curcuit varchar(50) ,
license_territory LicenseTerritory [varchar](50) ,
forest Forest varchar(50) ,
association Association varchar(50),
hunt_ar Hunt_Ar varchar(50) ,
area Area varchar(50) ,
contract Contract varchar(50) ,
radio_frequency RadioFrequency varchar(50)
)

This error happens:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'CHANGE'.

So.. I here I tried it to Alter table Change Old column name new column name datatype .. but here I receive the error

Upvotes: 4

Views: 9815

Answers (2)

Nalaka526
Nalaka526

Reputation: 11464

Try

EXEC sp_RENAME 'Users.username', 'UserName', 'Column'
...

Upvotes: 3

Adriaan Stander
Adriaan Stander

Reputation: 166326

Have a closer look at the Syntax

ALTER TABLE (Transact-SQL)

If I am not mistaken it is ALTER COLUMN, not CHANGE COLUMN

Further more you should probably have a read here

SQL SERVER – How to Rename a Column Name or Table Name

Upvotes: 0

Related Questions