SQL帮助文档中提供了重命名列的方法,下边整理如下:
下例将表 customers 中的列 contact title 重命名为 title。
EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
示例:在库中建一存储过程
create procedure col_rename
@oldcol varchar(100),
@newcol varchar(50)
as
set @oldcol = rtrim(@oldcol)
EXEC sp_rename @oldcol,@newcol,'COLUMN'
ASP调用:
dim oldcol as string
dim newcol as string
oldcol = "table1.[xxx]"
newcol = 'yyy'
connstr=Application("connstr")
set conn = Server.CreateObject("ADODB.Connection")
conn.open connstr
set cmd=Server.CreateObject("ADODB.command")
set cmd.activeconnection=conn
cmd.commandtype="4"
cmd.commandtext='exec col_rename '"+oldcol +"','"+newcol +"''
set rs=cmd.execute()