sp_rename修改对象名称

create table test(username varchar(10), userinfo varchar(200), primary key (username) ) 
go
--修改字段名
exec sp_rename 'test.userinfo', 'userdesc', 'column';
go
sp_help test
go
--修改表名
exec sp_rename 'test', 'test1', 'object';
go
sp_help test1
go
--sp_rename
/*
DOCUMENTATION:
[1] To rename a table, the @objname (meaning OldName) parm can be
passed in totally unqualified or fully qualified.
[2] The SA or DBO can rename objects owned by lesser users,
without the need for SetUser.
[3] The Owner portion of a qualified name can usually be
passed in in the omitted form (as in MyDb..MyTab or MyTab). The
typical exception is when the SA/DBO is trying to rename a table
where the @objname is present twice in sysobjects as a table
owned only by two different lesser users; requiring an explicit
owner qualifier in @objname.
[4] An unspecified Owner qualifier will default to the
current user if doing so will either resolve what would
otherwise be an ambiguity within @objtype, or will result
in exactly one match.
[5] If Database is part of the qualified @objname,
then it must match the current database. The @newname parm can
never be qualified.
[6] Here are the valid @objtype values. They correspond to
system tables which track each type:
'column' 'database' 'index' 'object' 'userdatatype'
The @objtype parm is sometimes required. It is always required
for databases. It is required whenever ambiguities would
otherwise exist. Explicit use of @objtype is always encouraged.
[7] Parms can use quoted_identifiers. For example:
Execute sp_rename 'amy."his table"','"her table"','object'
*/



你可能感兴趣的:(name)