惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security @ Cisco Blogs
小众软件
小众软件
D
Docker
博客园_首页
A
About on SuperTechFans
P
Privacy International News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
A
Arctic Wolf
Spread Privacy
Spread Privacy
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Latest news
Latest news
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
大猫的无限游戏
大猫的无限游戏
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
V2EX - 技术
V2EX - 技术
SecWiki News
SecWiki News
U
Unit 42
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LINUX DO - 热门话题
S
Security Affairs
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
博客园 - 【当耐特】
The GitHub Blog
The GitHub Blog
T
Tenable Blog
W
WeLiveSecurity
Cloudbric
Cloudbric
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
N
News and Events Feed by Topic
D
DataBreaches.Net
P
Proofpoint News Feed
B
Blog RSS Feed
B
Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - 阿哲

将Visio文件装换成HTML文件(在服务器上转换,客户端无需安装visio即可查看) string:值类型?引用类型?[转] SqlServer2005常用sql语句 SQL中FOR XML子句的各种用法 获得Windows中文件类型名称 完成类似QQ邮箱中‘HTML方式查看’功能查看Office文件 vs2008生成自定义dll,VS2008发布、生成网站时设置固定的dll文件名 开源.Net CMS系统 [转] 测试使用Windows Live Writter写Blog 试用Windows Live Mail OutlookExpress使用技巧 剩余的GMail邀请 实体类+自定义控件=? 用反射+特性列出所有的枚举变量及其描述信息,绑定到DropDownList上。 有关.NET和RS232设备通讯 .NET资源(收藏) 转:使用P/Invoke来开发用于与串行设备通讯的.NET基类(翻译) 最近有空,研究了一下.NET的通讯方面 实体和实体的集合-续2
SqlServer 2005 快速设置字段/表 的描述字段
阿哲 · 2009-05-26 · via 博客园 - 阿哲

在做数据库设计的时候,字段/表的 描述/备注 字段设置非常重要,在使用orm工具生成代码的时候也要读取 描述/备注 的内容,当然在设计器的时候添加这些信息还是比较方便的,但是使用sql脚本的时候,看起来就很复杂了。

我先想能不能直接在create table的时候直接添加描述字段,不过找遍了sql的语法也不支持这种写法,使用sp_addextendedproperty 我又感觉太麻烦,很多没必要的参数设置,于是自己写了一个存储过程来进行快速的设置:

Code
/****** 对象:  StoredProcedure [dbo].[SetDescription]    脚本日期: 05/22/2009 13:46:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE dbo.SetDescription
(
    
@Description sql_variant,
    
@TableName sysname,
    
@ColumnName sysname=NULL
)
AS
BEGIN
    
IF (@ColumnName IS NULL)
      
BEGIN
        
IF EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description', N'USER',N'dbo', N'TABLE',@TableNameNULLNULL))
            
EXEC sp_dropextendedproperty @name=N'MS_Description'@level0type=N'USER',@level0name=N'dbo'@level1type=N'TABLE',@level1name=@TableName
        
EXEC sp_addextendedproperty @name=N'MS_Description'@value=@Description@level0type=N'USER',@level0name=N'dbo'@level1type=N'TABLE',@level1name=@TableName
      
END
    
ELSE
      
BEGIN 
        
IF EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description', N'USER',N'dbo', N'TABLE',@TableName, N'COLUMN',@ColumnName))
            
EXEC sp_dropextendedproperty @name=N'MS_Description'@level0type=N'USER',@level0name=N'dbo'@level1type=N'TABLE',@level1name=@TableName@level2type=N'COLUMN',@level2name=@ColumnName    
        
EXEC sp_addextendedproperty @name=N'MS_Description'@value=@Description@level0type=N'USER',@level0name=N'dbo'@level1type=N'TABLE',@level1name=@TableName@level2type=N'COLUMN',@level2name=@ColumnName
      
END
END
GO

使用如下:

EXEC dbo.SetDescription N'功能描述',N'sys_Functions',N'FRemark'  --更改表 sys_Functions 的字段 FRemark 的描述为:功能描述
EXEC dbo.SetDescription N'功能表',N'sys_Functions'            --更改表 sys_Functions 的描述为:功能表
GO