Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
1.50/5 (4 votes)
hi all,

i am trying to change column name in sql2008 from StudentId to SID .
i am using this query :
SQL
alter table Student
rename column StudentId to SID

By using this not altered the table column .
so that please any one help to me.
thanks in advance

regarding ,
naresh
Posted
Updated 30-Jul-19 20:36pm
v3
Comments
walterhevedeich 1-May-12 23:42pm    
Your syntax is for Oracle, and will not work on SQL Server. I suggest you take a look at the answer below.
satrio_budidharmawan 2-May-12 0:08am    
The question should be like this : "How to change column name in SQL Server with SQL Query".
Because SQL alone, stand for every Database engine

The column can be renamed using
SQL
SP_RENAME 'Student.StudentId', 'SID ', 'COLUMN'

as explained here
SQL SERVER – How to Rename a Column Name or Table Name[^]
 
Share this answer
 
Comments
walterhevedeich 1-May-12 23:42pm    
My 5!
VJ Reddy 2-May-12 0:11am    
Thank you, walterhevedeich.
Unareshraju 1-May-12 23:53pm    
thank u somuch reddy
by using this i solved my problem
"SP_RENAME 'Student.StudentID','SID'
GO"
VJ Reddy 2-May-12 0:11am    
You're welcome and thank you for accepting the solution.
Shahin Khorshidnia 2-May-12 9:04am    
+5
select studentid as sid,sname,... into #temp from student
u just select all the columns and what ever column name u want to rename just give a name beside that column and import into another table .
 
Share this answer
 
exces sp_rename 'Persons.city','c_name', column
 
Share this answer
 
Query: - exec sp_rename 'new_tblencounter.encounter','encounter_dates','COLUMN' ;

It's Works.
 
Share this answer
 
v2
Comments
Richard Deeming 31-Jul-19 14:38pm    
Adds nothing to the accepted solution from 2012.

If you want to support that solution, either up-vote it, or add a comment to it. Don't repost it as a new solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900