SELECT d.name TableName,
a.colorder FieldNo,a.name FieldName,
(case when COLUMNPROPERTY( a.id,a.name,‘IsIdentity‘)=1 then ‘1‘else ‘0‘ end) IsIdentity,
(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 ‘1‘ else ‘0‘ end) IsPrimaryKey,
b.name as FieldType,
a.length as CharLength,
COLUMNPROPERTY(a.id,a.name,‘PRECISION‘) as FieldLength,
isnull(COLUMNPROPERTY(a.id,a.name,‘Scale‘),0) as DecimalDigits,
(case when a.isnullable=1 then ‘1‘else ‘0‘ end) IsNull,
isnull(g.[value],‘‘) AS Description ,
isnull(e.text,‘‘) DefaultValue
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 sys.extended_properties g on a.id=g.major_id AND a.colid = g.minor_id
where d.name =‘UserInfo‘
order by a.id,a.colorder
SQLServer2005+获取表结构信息
时间: 2024-10-25 20:30:47
SQLServer2005+获取表结构信息的相关文章
Oracle获取表结构信息:表名、是否视图、字段名、类型、长度、非空、主键
select a.TABLE_NAME as "TableName", case when (select count(*) from user_views v where v.VIEW_NAME =a.TABLE_NAME )>0 then 'V' else 'U'end as "TableType", a.COLUMN_NAME as "ColumnName", A.COLUMN_ID as "ColumnIndex"
mssql 获取表结构信息
SELECT (case when a.colorder=1 then d.name else null end) 表名, a.colorder 字段序号,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 sys
SQLServer2005,2000获取表结构:字段名、类型、长度、主键、非空、注释
SQLServer 2005 SELECT d.name N'TableName', d.xtype N'TableType', a.colorder N'ColumnIndex', a.name N'ColumnName', (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '1'else '0' end) N'IdnetityFG', (case when (SELECT count(*) FROM sysobjects
sql 2012中获取表的信息,包含字段的描述
1.获取数据库中的表 select name from sysobjects where type='U' 2.获取表字段(此处是Route表) Select name from syscolumns Where ID=OBJECT_ID('Route') 3.获取表中字段的描述 SELECT value FROM ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', 'Route', 'column', default) 4.获取表的
获取表的信息,包含字段的描述
--获取数据库中的表select name from sysobjects where type='U'--获取表字段 Select name from syscolumns ----------------------------------------------------------------------------------------------------------------------- --获取表的信息的所有信息,数据库中所有表的字段信息 select b.[value
SQL Server2008中通过SQL获取表结构
SQL Server2008中通过SQL获取表结构 新增数据用户,角色为public.映射到待获取表结构的数据库上,授与用户在该数据库上的身份为db_owner 运行例如以下SQL语句: select syscolumns.name as [Name] , systypes.name as [Type], syscolumns.length AS [Size], syscolumns.xprec As [Precision], ISNULL(syscolumns.scale, 0) AS [Sc
SqlServer获取表结构语句
--sql server 2005-- 1. 表结构信息查询 -- ========================================================================-- 表结构信息查询-- 邹建 2005.08(引用请保留此信息)-- ========================================================================SELECT TableName=CASE WHEN C.column_
使用JDBC connect获取数据库表结构信息
1.这是生成代码的关键 引入maven依赖 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.30</version> </dependency> 2.编写JAVA类 package com.yyj.mybties.jdbc; import java.sql.Conne
Sql中获取表结构(字段名称,类型,长度,说明)
在写代码生成器的时候遇到这样一个问题,想在搭建好数据库后把字段说明当做注释写进类文件里,所以我们在网上搜索到了许多代码很长很长的方法(当然我的代码也很长),亲测了一条简单易懂的语句,也是大多数转载的方法: SELECT TableName = OBJECT_NAME(c.object_id), ColumnsName = c.name, Description = ex.value, ColumnType=t.name, Length=c.max_length FROM sys.columns