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'
*/
复制代码



posted on   trams  阅读(496)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
< 2012年1月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11

统计

点击右上角即可分享
微信分享提示