1、获取表的基本字段属性





2、获取字段的描述信息则





















3、获取表的主外键
--获取表主外键约束
exec sp_helpconstraint '表名' ;
exec sp_helpconstraint '表名' ;
4、单独查询表的递增字段
--单独查询表递增字段
select [name] from syscolumns where
id=object_id(N'你的表名') and COLUMNPROPERTY(id,name,'IsIdentity')=1
select [name] from syscolumns where
id=object_id(N'你的表名') and COLUMNPROPERTY(id,name,'IsIdentity')=1
5、OBJECT_ID用法
作用:返回架构范围内对象的数据库对象标识号。
5.1 语法
OBJECT_ID ( '[ database_name . [ schema_name ] . | schema_name . ] object_name' [ ,'object_type' ] )
OBJECT_ID ( '[ database_name . [ schema_name ] . | schema_name . ] object_name' [ ,'object_type' ] )
5.2 参数
' object_name '
' object_name '
-
要使用的对象。object_name 的数据类型为 varchar 或 nvarchar。如果 object_name 的数据类型为 varchar,则它将隐式转换为 nvarchar。可以选择是否指定数据库和架构名称。
- ' object_type '
-
架构范围的对象类型。object_type 的数据类型为 varchar 或 nvarchar。如果 object_type 的数据类型为 varchar,则它将隐式转换为 nvarchar。
5.3 返回类型
int
int
5.4 备注
当该参数对系统函数可选时,则系统采用当前数据库、主机、服务器用户或数据库用户。内置函数后面必须跟圆括号。当指定临时表名时,除非当前数据库为 tempdb,否则必须在该临时表名之前加上数据库名称。
例如:SELECT OBJECT_ID('tempdb..#mytemptable')。
当该参数对系统函数可选时,则系统采用当前数据库、主机、服务器用户或数据库用户。内置函数后面必须跟圆括号。当指定临时表名时,除非当前数据库为 tempdb,否则必须在该临时表名之前加上数据库名称。
例如:SELECT OBJECT_ID('tempdb..#mytemptable')。
5.5 示例
以下示例返回 AdventureWorks 数据库中 Production.WorkOrder 表的对象 ID。
SELECT OBJECT_ID(N'AdventureWorks.Production.WorkOrder') AS 'Object ID';
6、 object_id(N'orders')中N的作用
这个数据类型是启用Unicode,如果字符串里