Hi,
Can I change the name of the column using alter command .
Is there any such option?
Provide me different ways of changing column name in a table.
Thanks & Regards,
Vani Jyothsna.From BOL
EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
"Jyothsna" <jyothsnat@.dev.visualsoft-tech.com> wrote in message
news:uk8rWF9TFHA.752@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Can I change the name of the column using alter command .
> Is there any such option?
> Provide me different ways of changing column name in a table.
> Thanks & Regards,
> Vani Jyothsna.
>|||Hi Jyothsna:
Here is the solution for your problem:
EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
This example renames the contact title column in the customers table to titl
e.
Hope this answers the question
thanks and regards
Chandra
"Jyothsna" wrote:
> Hi,
> Can I change the name of the column using alter command .
> Is there any such option?
> Provide me different ways of changing column name in a table.
> Thanks & Regards,
> Vani Jyothsna.
>
>|||Notice that using sp_rename, will not change the code that references this
column from views, stored procedures or functions.
Example:
use northwind
go
create table t1 (
c1 int
)
go
create procedure proc1
as
select c1 from t1
go
create view v1
as
select c1 from t1
go
create function f1()
returns table
as
return(select c1 from t1)
go
select
[text]
from
syscomments
where
(
object_name([id]) = 'proc1'
and objectproperty([id], 'IsProcedure') = 1
)
or
(
object_name([id]) = 'v1'
and objectproperty([id], 'IsView') = 1
)
or
(
object_name([id]) = 'f1'
and objectproperty([id], 'IsInlineFunction') = 1
)
go
exec sp_rename 't1.c1', 'c2', 'column'
go
select
table_name,
column_name
from
information_schema.columns
where
table_schema = 'dbo'
and table_name = 't1'
go
select
[text]
from
syscomments
where
(
object_name([id]) = 'proc1'
and objectproperty([id], 'IsProcedure') = 1
)
or
(
object_name([id]) = 'v1'
and objectproperty([id], 'IsView') = 1
)
or
(
object_name([id]) = 'f1'
and objectproperty([id], 'IsInlineFunction') = 1
)
go
drop procedure proc1
go
drop view v1
go
drop function f1
go
drop table t1
go
AMB
"Jyothsna" wrote:
> Hi,
> Can I change the name of the column using alter command .
> Is there any such option?
> Provide me different ways of changing column name in a table.
> Thanks & Regards,
> Vani Jyothsna.
>
>|||Several items have been thrown out there but I woul add that it i not
suggested you rename a column in a production system as there are not only
internal references to worry about but external (consider any effects on
existing applications). If this is for reference you could use the column
description to put a note in or support of an application you might use a
view with the coulmn aliased.
"Jyothsna" wrote:
> Hi,
> Can I change the name of the column using alter command .
> Is there any such option?
> Provide me different ways of changing column name in a table.
> Thanks & Regards,
> Vani Jyothsna.
>
>
No comments:
Post a Comment