




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
= 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(sysname,),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)when = 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 (smallint,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) 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_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 & 0x800) = 0x800and ( = 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_name, 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_table_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 master with no_loggoprint creating sp_server_infogocreate proc sp_server_info (attribute_id int = null)asif attribute_id is not nullselect *from master.dbo.spt_server_infowhere attribute_id = attribute_idelseselect *from master.dbo.spt_server_infoorder by attribute_idgogrant execute on sp_server_info to publicgodump tran master with no_loggoprint creating sp_special_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 full_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 nullbeginraiserror 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 /* 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 query */SELECTSCOPE = convert(smallint,NULL),COLUMN_NAME = convert(varchar(32),),DATA_TYPE = convert(smallint, -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 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.status&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 iWHEREstatus&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,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,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,c2.colid)AND c.id = x.idAND c2.id = x.idAND c2.colid keycnt+(x.status&16)/16AND x.indid = indidAND t.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 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) = 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 = 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 /* If qualifier doesnt match current database */raiserror (15250, -1,-1)returnendendif 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 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 = table_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.status&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 iWHEREstatus&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) TYPE_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,SCALE = 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,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, version) = 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 = null,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)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 /* If 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 = 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)if col_type = VBEGIN /* if ROWVER, just run that query */SELECTSCOPE = convert(smallint,NULL),COLUMN_NAME = convert(sysname,),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 = 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 = 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_id 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(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,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 = table_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),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) =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 奥数公开课件
- 奥巴马传课件
- 多边形画图课件
- 奥尔夫啄木鸟课件
- 医护协作关系的具体维度
- 大黄蜂飞行奥尔夫课件
- 龙口安全事故警示讲解
- 安全对策实施方案讲解
- 美好医患关系塑造
- 水利行业新质生产力发展
- 2025《煤矿安全规程》新旧对照专题培训
- 名著导读好书推荐读后感分享《绿野仙踪》PPT模(内容完整)板
- JJG 1036-2022电子天平
- FZ/T 64087-2022木棉纤维絮片
- GB/T 11379-2008金属覆盖层工程用铬电镀层
- CSCCP宫颈细胞病理学理论考试题
- 设计说明书玉米秸秆粉碎还田机
- 仪表专业现场仪表知识
- 【课件】1.1精微广大-绘画的功能与分类课件-2021-2022学年高中美术人美版(2019)选修绘画
- 自然辩证法 精品课课件 (全套讲义)
- 《小班幼儿生活自理能力存在的问题与对策(论文)11000字》
评论
0/150
提交评论