版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、= quotename(table_owner)endelsebeginSELECT full_table_name = quotename(table_owner) +. + quotename(table_name)endend/* Get Object ID */SELECT table_id = object_id(full_table_name)selectTABLE_QUALIFIER = convert(sysname,db_name(),TABLE_OWNER = convert(sysname,user_name(o.uid),TABLE_NAME = convert(sys
2、name,),COLUMN_NAME = convert(sysname,),KEY_SEQ =casewhen = index_col(full_table_name, i.indid, 1) then convert (smallint,1)when = index_col(full_table_name, i.indid, 2) then convert (smallint,2)when = index_col(full_table_name, i.indid, 3) then convert (smallint,3)wh
3、en = index_col(full_table_name, i.indid, 4) then convert (smallint,4)when = index_col(full_table_name, i.indid, 5) then convert (smallint,5)when = index_col(full_table_name, i.indid, 6) then convert (smallint,6)when = index_col(full_table_name, i.indid, 7) then convert (s
4、mallint,7)when = index_col(full_table_name, i.indid, 8) then convert (smallint,8)when = index_col(full_table_name, i.indid, 9) then convert (smallint,9)when = index_col(full_table_name, i.indid, 10) then convert (smallint,10)when = index_col(full_table_name, i.indid, 11)
5、then convert (smallint,11)when = index_col(full_table_name, i.indid, 12) then convert (smallint,12)when = index_col(full_table_name, i.indid, 13) then convert (smallint,13)when = index_col(full_table_name, i.indid, 14) then convert (smallint,14)when = index_col(full_table
6、_name, i.indid, 15) then convert (smallint,15)when = index_col(full_table_name, i.indid, 16) then convert (smallint,16)end,PK_NAME = convert(sysname,)fromsysindexes i, syscolumns c, sysobjects o -, syscolumns c1whereo.id = table_idand o.id = c.idand o.id = i.idand (i.status & 0 x800) =
7、0 x800and ( = index_col (full_table_name, i.indid, 1) = index_col (full_table_name, i.indid, 2) = index_col (full_table_name, i.indid, 3) = index_col (full_table_name, i.indid, 4) = index_col (full_table_name, i.indid, 5) = index_col (full_table_nam
8、e, i.indid, 6) = index_col (full_table_name, i.indid, 7) = index_col (full_table_name, i.indid, 8) = index_col (full_table_name, i.indid, 9) = index_col (full_table_name, i.indid, 10) = index_col (full_table_name, i.indid, 11) = index_col (full_t
9、able_name, i.indid, 12) = index_col (full_table_name, i.indid, 13) = index_col (full_table_name, i.indid, 14) = index_col (full_table_name, i.indid, 15) = index_col (full_table_name, i.indid, 16)order by 1, 2, 3, 5gogrant execute on sp_pkeys to publicgodump tran m
10、aster with no_loggoprint creating sp_server_infogocreate proc sp_server_info (attribute_id int = null)asif attribute_id is not nullselect *where attribute_id = attribute_idelseselect *order by attribute_idgogrant execute on sp_server_info to publicgodump tran master with no_loggoprint creating sp_sp
11、ecial_columnsgo/* Procedure for pre-6.0 server */CREATE PROCEDURE sp_special_columns (table_name varchar(32),table_owner varchar(32) = null,table_qualifier varchar(32) = null,col_type char(1) = R,scope char(1) = T,nullable char(1) = U,ODBCVer int = 2)ASDECLARE indid intDECLARE table_id intDECLARE fu
12、ll_table_name varchar(65) /* 2*32+1 */DECLARE scopeout smallintif col_type not in (R,V) or col_type is nullbeginraiserror 20002 Rush_42returnendif scope = Cselect scopeout = 0else if scope = Tselect scopeout = 1elsebeginraiserror 20002 Rush_43returnendif nullable not in (U,O) or nullable is nullbegi
13、nraiserror 20002 Rush_44returnendif table_qualifier is not nullbeginif db_name() table_qualifierbegin /* If qualifier doesnt match current database */raiserror 20001 Rush_5returnendendif table_owner is nullbegin /* If unqualified table name */SELECT full_table_name = table_nameendelsebegin /* Qualif
14、ied table name */SELECT full_table_name = table_owner + . + table_nameend/* Get Object ID */SELECT table_id = object_id(full_table_name)if col_type = VBEGIN /* if ROWVER, just run that query */SELECTSCOPE = convert(smallint,NULL),COLUMN_NAME = convert(varchar(32),),DATA_TYPE = convert(smallint
15、, -3),TYPE_NAME = ,PRECISION = convert(int,8),LENGTH = convert(int,8),SCALE = convert(smallint, NULL),PSEUDO_COLUMN = convert(smallint,1)FROMsystypes t, syscolumns cWHEREc.id = table_idAND c.usertype = 80 /* TIMESTAMP */AND t.usertype = 80 /* TIMESTAMP */RETURNEND/* ROWID, now find the id of t
16、he best index for this table */IF nullable = O /* Dont include any indexes that containnullable columns. */SELECT indid = MIN(indid)FROM sysindexes i,syscolumns c,syscolumns c2WHEREi.status&2 = 2 /* If Unique Index */AND c.id = i.idAND c2.id = c.idAND c2.colid 0 /* Eliminate Table Row */AND =
17、 index_col(table_name,i.indid,c2.colid)GROUP BY indid HAVING SUM(c.status&8) = 0ELSE /* Include indexes that are partially nullable. */SELECT indid = MIN(indid)FROM sysindexes iWHEREstatus&2 = 2 /* If Unique Index */AND id = table_idAND indid 0 /* Eliminate Table Row */SELECTSCOPE = scopeout,COLUMN_
18、NAME = convert(varchar(32),INDEX_COL(full_table_name,indid,c2.colid),d.DATA_TYPE,TYPE_NAME = ,PRECISION = isnull(d.data_precision, convert(int,c.length),LENGTH = isnull(d.length, convert(int,c.length),SCALE = d.numeric_scale,PSEUDO_COLUMN = convert(smallint,1)FROMsysindexes x,syscolumns c,mast
19、er.dbo.spt_datatype_info d,systypes t,syscolumns c2 /* Self-join to generate list of index columns and */* to extract datatype names */WHEREx.id = table_idAND = INDEX_COL(full_table_name,indid,c2.colid)AND c.id = x.idAND c2.id = x.idAND c2.colid keycnt+(x.status&16)/16AND x.indid = indidAND t
20、.type = d.ss_dtypeAND c.length = d.fixlenAND c.usertype = t.usertypegoif (charindex(6.00, version) = 0 andcharindex(6.50, version) = 0 andcharindex(7.00, version) = 0 andcharindex(8.00, version) = 0)beginprint print print Warning:print you are installing the stored procedures print on a pre 6.0 SQL
21、Server.print Ignore the following errors.endelsedrop proc sp_special_columnsgo/* Procedure for 6.0 and 6.50 servers */CREATE PROCEDURE sp_special_columns (table_name varchar(32),table_owner varchar(32) = null,table_qualifier varchar(32) = null,col_type char(1) = R,scope char(1) = T,nullable char(1)
22、= U,ODBCVer int = 2)ASDECLARE indid intDECLARE table_id intDECLARE full_table_name varchar(65) /* 2*32+1 */DECLARE scopeout smallintif col_type not in (R,V) or col_type is nullbeginraiserror (15251,-1,-1,col_type,R or V)returnendif scope = Cselect scopeout = 0else if scope = Tselect scopeout = 1else
23、beginraiserror (15251,-1,-1,scope,C or T)returnendif nullable not in (U,O) or nullable is nullbeginraiserror (15251,-1,-1,nullable,U or O)returnendif table_qualifier is not nullbeginif db_name() table_qualifierbegin /* If qualifier doesnt match current database */raiserror (15250, -1,-1)returnendend
24、if table_owner is nullbegin /* If unqualified table name */SELECT full_table_name = table_nameendelsebegin /* Qualified table name */SELECT full_table_name = table_owner + . + table_nameend/* Get Object ID */SELECT table_id = object_id(full_table_name)if col_type = VBEGIN /* if ROWVER, just run that
25、 query */SELECTSCOPE = convert(smallint,NULL),COLUMN_NAME = convert(varchar(32),),DATA_TYPE = convert(smallint, -2),TYPE_NAME = ,PRECISION = convert(int,8),LENGTH = convert(int,8),SCALE = convert(smallint, NULL),PSEUDO_COLUMN = convert(smallint,1)FROMsystypes t, syscolumns cWHEREc.id = t
26、able_idAND c.usertype = 80 /* TIMESTAMP */AND t.usertype = 80 /* TIMESTAMP */RETURNEND/* ROWID, now find the id of the best index for this table */IF nullable = O /* Dont include any indexes that containnullable columns. */SELECT indid = MIN(indid)FROM sysindexes i,syscolumns c,syscolumns c2WHEREi.s
27、tatus&2 = 2 /* If Unique Index */AND c.id = i.idAND c2.id = c.idAND c2.colid 0 /* Eliminate Table Row */AND = index_col(table_name,i.indid,c2.colid)GROUP BY indid HAVING SUM(c.status&8) = 0ELSE /* Include indexes that are partially nullable. */SELECT indid = MIN(indid)FROM sysindexes iWHEREst
28、atus&2 = 2 /* If Unique Index */AND id = table_idAND indid 0 /* Eliminate Table Row */SELECTSCOPE = scopeout,COLUMN_NAME = convert(varchar(32),INDEX_COL(full_table_name,indid,c2.colid),d.DATA_TYPE,convert(varchar(32),casewhen (t.usertype 100 or t.usertype in (18,80)then else d.TYPE_NAMEend) TY
29、PE_NAME,convert(int,casewhen d.DATA_TYPE in (6,7) then d.data_precision /* FLOAT/REAL */else isnull(convert(int,c.prec), 2147483647)end) PRECISION,convert(int,casewhen d.ss_dtype IN (106, 108, 55, 63) then /* decimal/numeric types */convert(int,c.prec+2)elseisnull(d.length, c.length)end) LENGTH,SCAL
30、E = convert(smallint, c.scale),PSEUDO_COLUMN = convert(smallint,1)FROMsysindexes x,syscolumns c,master.dbo.spt_datatype_info d,systypes t,syscolumns c2 /* Self-join to generate list of index columns and */* to extract datatype names */WHEREx.id = table_idAND = INDEX_COL(full_table_name,indid,
31、c2.colid)AND c.id = x.idAND c2.id = x.idAND c2.colid x.keycnt+(x.status&16)/16AND x.indid = indidAND t.type = d.ss_dtypeAND (d.ODBCVer is null or d.ODBCVer = ODBCVer)AND isnull(d.AUTO_INCREMENT,0) = (c.status&128)/128AND c.usertype = t.usertypegoif (charindex(7.00, version) = 0 andcharindex(8.00, ve
32、rsion) = 0)beginprint print print Warning:print you are installing the stored procedures print on a pre 7.0 SQL Server.print Ignore the following errors.endelsedrop proc sp_special_columnsgo/* Procedure for 7.0 servers */CREATE PROCEDURE sp_special_columns (table_name sysname,table_owner sysname = n
33、ull,table_qualifier sysname = null,col_type char(1) = R,scope char(1) = T,nullable char(1) = U,ODBCVer int = 2)ASDECLARE indid intDECLARE table_id intDECLARE full_table_name nvarchar(257)DECLARE scopeout smallintif col_type not in (R,V) or col_type is nullbeginraiserror (15251,-1,-1,col_type,R or V)
34、returnendif scope = Cselect scopeout = 0else if scope = Tselect scopeout = 1elsebeginraiserror (15251,-1,-1,scope,C or T)returnendif nullable not in (U,O) or nullable is nullbeginraiserror (15251,-1,-1,nullable,U or O)returnendif table_qualifier is not nullbeginif db_name() table_qualifierbegin /* I
35、f qualifier doesnt match current database */raiserror (15250, -1,-1)returnendendif table_owner is nullbegin /* If unqualified table name */SELECT full_table_name = quotename(table_name)endelsebegin /* Qualified table name */if table_owner = begin /* If empty owner name */SELECT full_table_name = quo
36、tename(table_owner)endelsebeginSELECT full_table_name = quotename(table_owner) +. + quotename(table_name)endend/* Get Object ID */SELECT table_id = object_id(full_table_name)if col_type = VBEGIN /* if ROWVER, just run that query */SELECTSCOPE = convert(smallint,NULL),COLUMN_NAME = convert(sysname,c.
37、name),DATA_TYPE = convert(smallint, -2),TYPE_NAME = ,PRECISION = convert(int,8),LENGTH = convert(int,8),SCALE = convert(smallint, NULL),PSEUDO_COLUMN = convert(smallint,1)FROMsystypes t, syscolumns cWHEREnot (table_id is null)AND c.id = table_idAND = timestamp /* TIMESTAMP */AND t.xtype
38、 = c.xtypeAND t.xusertype = c.xusertypeRETURNEND/* ROWID, now find the id of the best index for this table */IF nullable = O /* Dont include any indexes that containnullable columns. */SELECT indid = MIN(indid)FROM sysindexes x, syscolumns c, syscolumns c2WHEREnot (table_id is null)AND x.status&2 =
39、2 /* If Unique Index */AND c.id = x.idAND c2.id = c.idAND c2.colid 0 /* Eliminate Table Row */AND = index_col(table_name,x.indid,c2.colid)GROUP BY indid HAVING SUM(c.status&8) = 0ELSE /* Include indexes that are partially nullable. */SELECT indid = MIN(indid)FROM sysindexes xWHEREnot (table_i
40、d is null)AND status&2 = 2 /* If Unique Index */AND id = table_idAND indid 0 /* Eliminate Table Row */SELECTSCOPE = scopeout,COLUMN_NAME = convert(sysname,INDEX_COL(full_table_name,indid,c2.colid),d.DATA_TYPE,convert(sysname,casewhen t.xusertype 255 then else d.TYPE_NAMEend) TYPE_NAME,convert(
41、int,casewhen d.DATA_TYPE in (6,7) then d.data_precision /* FLOAT/REAL */else OdbcPrec(c.xtype,c.length,c.xprec)end) PRECISION,convert(int,casewhen type_name(d.ss_dtype) IN (numeric,decimal) then /* decimal/numeric types */OdbcPrec(c.xtype,c.length,c.xprec)+2else isnull(d.length, c.length)end) LENGTH
42、,SCALE = convert(smallint, OdbcScale(c.xtype,c.xscale),PSEUDO_COLUMN = convert(smallint,1)FROMsysindexes x,syscolumns c,master.dbo.spt_datatype_info d,systypes t,syscolumns c2 /* Self-join to generate list of index columns and */* to extract datatype names */WHEREnot (table_id is null)AND x.id = tab
43、le_idAND = INDEX_COL(full_table_name,indid,c2.colid)AND c.id = x.idAND c2.id = x.idAND c2.colid x.keycnt + (x.status&16)/16AND x.indid = indidAND t.xtype = d.ss_dtypeAND (d.ODBCVer is null or d.ODBCVer = ODBCVer)AND isnull(d.AUTO_INCREMENT,0) = isnull(ColumnProperty (c.id, , IsIdentity)
44、,0)AND c.xusertype = t.xusertypegoif (charindex(8.00, version) = 0)beginprint print print Warning:print you are installing the stored procedures print on a pre 8.0 SQL Server.print Ignore the following errors.endelsedrop proc sp_special_columnsgo/* Procedure for 8.0 and later servers */CREATE PROCEDURE sp_special_columns (table_name sysname,table_owner sysname = null,table_qualifier sysname = null,col_type char(1) = R,sco
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024版学历提升服务合同协议书范文
- 专业版2024年植筋施工分包协议模板版B版
- 2024版保密与竞业禁止协议
- 万达商业广场2024年合作经营协议样本版B版
- 个人参股协议模板2024年版版B版
- 供应链服务创新与客户满意度提升策略考核试卷
- 上海2024年上海长江剧场(上海市宛平艺苑)招聘笔试历年典型考点(频考版试卷)附带答案详解
- 合同法律风险防范考核试卷
- 2025年中国附接法兰市场调查研究报告
- 2025至2031年中国超薄板行业投资前景及策略咨询研究报告
- 标准编写培训
- 外立面改造专项施工方案
- GB/T 4354-2008优质碳素钢热轧盘条
- GB 29518-2013柴油发动机氮氧化物还原剂尿素水溶液(AUS 32)
- 《中国国家处方集》附录
- 消防安全值班制度
- 智慧教育典型案例:依托智慧教学 优化英语课堂
- 伟星管-云上装饰
- 生活饮用水消毒剂和消毒设备卫生安全评价规范(2019年版)
- 施工现场重大危险源公示牌
- 养老院老年人误食误服防范措施及应急预案
评论
0/150
提交评论