MSSQL中数据库对象类型解释

public string GetObjectTypeName(object oType)
{
switch (oType+"")
{
case "U":
return "用户表";
case "V":
return "视图";
case "P":
return "存储过程";
case "TF":
return "表函数";
case "FN":
return "标量函数";
case "C":
return "CHECK约束";
case "D":
return "默认值或DEFAULT约束 ";
case "F":
return "FOREIGN KEY 约束 ";
case "IF":
return "内嵌表函数 ";
case "K":
return "PRIMARY KEY或 UNIQUE约束";
case "L":
return "日志";
case "R":
return "规则";
case "RF":
return "复制筛选存储过程";
case "S":
return "系统表";
case "TR":
return "触发器";
case "X":
return "扩展存储过程";
}
return "";
}
查询数据库脚本:
SELECT name AS DbName,[dbid] As DbId,filename As FileName FROM [Master].dbo.[sysdatabases] Where dbid>4 Order by name

查询表脚本:
SELECT [{0}].dbo.sysobjects.name As TableName,id As TableId,
(Select top 1 rowcnt From [{0}].dbo.sysindexes Where id=[{0}].dbo.sysobjects.id) As RecordCount,
ISNULL(E.name,‘‘) As PropertyName,
ISNULL(E.value,‘‘) As PropertyValue
FROM [{0}].dbo.sysobjects
LEFT JOIN sys.extended_properties E ON E.major_id=[{0}].dbo.sysobjects.id AND E.minor_id=0
Where xtype=‘U‘ AND [{0}].dbo.sysobjects.name not in (‘dtproperties‘,‘sysdiagrams‘) Order By [{0}].dbo.sysobjects.name

查询数据库对象脚本:
SELECT T.name As ObjectName,T.id As ObjectId,rTRIM(T.xtype) AS ObjectType,
(SELECT Top 1 A.[definition] FROM [{0}].sys.sql_modules A JOIN [{0}].sys.objects B ON A.object_id = B.object_id
Where B.name=T.name) As ObjectDefinition
FROM [{0}].dbo.sysobjects T
Where xtype in ( N‘P‘, N‘PC‘,N‘FN‘, N‘IF‘, N‘TF‘, N‘FS‘, N‘FT‘, N‘V‘,N‘TR‘)
AND T.name not in (‘dtproperties‘,‘sysdiagrams‘)
Order By T.name

查询列与字段:
Select
C.name As TableName,
C.id As TableObjectId,
A.name As ColumnName,
A.colid As ColumnObjectId,
A.[length] As ColumnLength,
B.name As ColumnDataType,
ISNULL(D.[text],‘‘) AS DefaultValue,
ISNULL(E.name,‘‘) As PropertyName,
ISNULL(E.value,‘‘) As PropertyValue,
COLUMNPROPERTY(A.id,A.name, ‘AllowsNULL‘) AS AllowsNull,
COLUMNPROPERTY(A.id,A.name, ‘IsCursorType‘) AS IsCursorType,
COLUMNPROPERTY(A.id,A.name, ‘IsIdentity‘) AS IsIdentity,
(Select Count(1) From
sysobjects
INNER JOIN sysindexes ON sysobjects.parent_obj=sysindexes.id AND sysobjects.name=sysindexes.name
INNER JOIN sysindexkeys ON sysindexes.id=sysindexkeys.id AND sysindexes.indid=sysindexkeys.indid
Where sysobjects.xtype=‘PK‘ AND sysobjects.parent_obj=A.id AND sysindexkeys.colid=A.colid) AS IsPrimaryKey
From
dbo.syscolumns A
INNER JOIN dbo.systypes B ON B.xusertype=A.xtype
INNER JOIN dbo.sysobjects C ON C.id=A.id AND C.xtype IN (‘U‘,‘V‘) AND C.name not in (‘dtproperties‘,‘sysdiagrams‘)
LEFT JOIN dbo.syscomments D ON A.cdefault = D.id
LEFT JOIN sys.extended_properties E ON E.major_id=A.id AND E.minor_id=A.colid order by A.colid

查询约束脚本:
SELECT
b.rkeyid AS MasterTableObjectId,
object_name(b.rkeyid) AS MasterTableName,
b.rkey As MasterColumnObjectId,
(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid) AS MasterColumnName,
b.fkeyid AS ForeignTableObjectId,
object_name(b.fkeyid) AS ForeignTableName,
b.fkey AS ForeignColumnObjectId,
(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid) As ForeignColumnName,
ObjectProperty(a.id,‘CnstIsUpdateCascade‘) AS UpdateCascade,
ObjectProperty(a.id,‘CnstIsDeleteCascade‘) AS DeleteCascade
FROM sysobjects a
join sysforeignkeys b on a.id=b.constid
join sysobjects c on a.parent_obj=c.id
WHERE a.xtype=‘F‘ AND c.xtype=‘U‘

参考:

http://blog.ueren.com/?tag=sysobjects

时间: 2024-10-10 14:41:30

MSSQL中数据库对象类型解释的相关文章

(转)JavaScript中判断对象类型的种种方法

我们知道,JavaScript中检测对象类型的运算符有:typeof.instanceof,还有对象的constructor属性: 1) typeof 运算符 typeof 是一元运算符,返回结果是一个说明运算数类型的字符串.如:"number","string","boolean","object","function","undefined"(可用于判断变量是否存在). 但 type

jquery中关于对象类型的判断原理

class2type[ core_toString.call(obj) ] jquery中关于对象类型的判断原理 jquery源码中关于类型判断的工具函数为type,调用方法为$.type()或者jQuery.type(),关于type函数的实现为: 1 type: function( obj ) { 2 if ( obj == null ) { 3 return String( obj ); 4 } 5 // Support: Safari <= 5.1 (functionish RegExp

MSSQL 获取数据库字段类型

1 SELECT 2 col.name AS 列名, 3 typ.name as 数据类型, 4 col.max_length AS 占用字节数, 5 col.precision AS 数字长度, 6 col.scale AS 小数位数, 7 col.is_nullable AS 是否允许非空, 8 col.is_identity AS 是否自增, 9 case when exists 10 ( SELECT 1 11 FROM 12 sys.indexes idx 13 join sys.in

Python中的对象类型的初步介绍

一:介绍 1.为什么使用内置对象 对象类型是语言的一个部分 内置对象构成了每个python程序的核心部分 2.核心数据类型 数字 字符串 列表 字典 元组 文件 集合 其他类型 编程单元类型 与实现相关的类型 二:数字 1.**是乘方 2.math数学模块 3.random模块 三:字符串 1.介绍 字符串是单个

批量修改Sqlserver中数据库对象的所属架构

执行以下SQL,将执行结果拷贝出来,批量执行既可. SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name FROM sys.Procedures p INNER JOIN sys.Schemas s on p.schema_id = s.schema_id WHERE s.Name = '旧的架构名称' 注:标红字为对象类型,如果为表,换成Tables 执行完以上语句,将执行结果放到执行窗口再次执行. ALTER SCHEMA d

继承中的对象类型转化以及程序运行步骤

1class Parent{ 2 3          int x=10; 4          public Parent(){ 5               add(2); 6          } 7          void add(int y){ 8               x+=y; 9          }10     }1112     class Child extends Parent{13          int x=9;14          void add(

iOS中 判断对象类型的一些方法

-(BOOL)  isKindOf:class 表示:对象是否为class或其父类 -(BOOL) isMemberOf:class 表示:对象是否为class -(BOOL) respondsToSelector:selector 表示:对象是否能够响应selector指定的方法 -(BOOL) instanceRespondToSelector:selector 表示:指定的对象是否能响应selector? -(BOOL) isSubclassOfClass:class 表示:对象是clas

SQL中的JOIN类型解释(CROSS, INNER,OUTER),关键字ON,USING

书上讲得明白,解了不少迷惑. SELECT e.fname, e.lname, d.name FROM employee AS e INNER JOIN department AS d ON e.dept_id = d.dept_id; SELECT e.fname, e.lname, d.name FROM employee AS e INNER JOIN department AS d USING (dept_id);

js中推断对象详细类型

大家可能知道js中推断对象类型能够用typeof来推断. 看以下的情况 <script> alert(typeof 1);//number alert(typeof "2");//string alert(typeof [1,2,3]);//object alert(typeof {"name":"zhuhui"})//object </script> 从上面中我们能够看出数组和普通对象用typeof推断出来都是objec