几段SQL Server语句和存储过程

2016-02-19 21:19 7 1 收藏

今天给大家分享的是由图老师小编精心为您推荐的几段SQL Server语句和存储过程,喜欢的朋友可以分享一下,也算是给小编一份支持,大家都不容易啊!

【 tulaoshi.com - 编程语言 】

  -- ======================================================

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

  --列出SQL SERVER 所有表,字段名,主键,类型,长度,小数位数等信息

  --在查询分析器里运行即可,可以生成一个表,导出到EXCEL中

  -- ======================================================

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

  SELECT

  (case when a.colorder=1 then d.name else '' end)表名,

  a.colorder 字段序号,

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

  a.name 字段名,

  (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,

  (case when (SELECT count(*)

  FROM sysobjects

  WHERE (name in

  (SELECT name

  FROM sysindexes

  WHERE (id = a.id) AND (indid in

  (SELECT indid

  FROM sysindexkeys

  WHERE (id = a.id) AND (colid in

  (SELECT colid

  FROM syscolumns

  WHERE (id = a.id) AND (name = a.name))))))) AND

  (xtype = 'PK'))0 then '√' else '' end) 主键,

  b.name 类型,

  a.length 占用字节数,

  COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,

  isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,

  (case when a.isnullable=1 then '√'else '' end) 允许空,

  isnull(e.text,'') 默认值,

  isnull(g.[value],'') AS 字段说明  

  FROM syscolumns a left join systypes b

  on a.xtype=b.xusertype

  inner join sysobjects d

  on a.id=d.id and d.xtype='U' and d.name'dtproperties'

  left join syscomments e

  on a.cdefault=e.id

  left join sysproperties g

  on a.id=g.id AND a.colid = g.smallid 

  order by a.id,a.colorder

  -------------------------------------------------------------------------------------------------

  列出SQL SERVER 所有表、字段定义,类型,长度,一个值等信息

  并导出到Excel 中

  -- ======================================================

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

  -- Export all user tables definition and one sample value

  -- jan-13-2003,Dr.Zhang

  -- ======================================================

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

来源:http://www.tulaoshi.com/n/20160219/1625886.html

延伸阅读
标签: SQLServer
/*备份数据库的过程*/ if exists(  select * from sysobjects   where name=’pr_backup_db’ and xtype=’p’           ) begin  drop proc pr_backup_db end go create proc pr_backup_db @flag&n...
--有输入参数的存储过程--create proc GetComment(@commentid int)asselect * from Comment where CommentID=@commentid --有输入与输出参数的存储过程--create proc GetCommentCount@newsid int,@count int outputasselect @count=count(*) from Comment where NewsID=@newsid --返回单个值的函数--create function MyFunction(@newsid int)...
标签: ASP
  建立表: CREATE TABLE [TestTable] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , [LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , [Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [Note] [nvarchar] (2000) COLLATE Chinese_PRC_CI_...
标签: SQLServer
  存储过程、存储函数的加密:WITH ENCRYPTION <!--[if !supportLineBreakNewLine]-- <!--[endif]-- CREATE procedure dbo.sp_XML_main @table_name nvarchar(260)='', @dirname nvarchar(20)='' WITH ENCRYPTION as begin .................................................... end go     存储过程、存...
标签: Web开发
1.新建表: CREATE TABLE [mytest] (     [id] [int] NOT NULL ,     [name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,     [phone] [varchar] (13) COLLATE Chinese_PRC_CI_AS NULL ,     [addr] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY] G...

经验教程

149

收藏

54
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部