SQL Doc获取表结构信息的SQL
2009-08-29 00:00:00 来源:WEB开发网最后一行Where so.NAME='schools',是只获取表名为Schools的信息,把这个Where条件去掉,则获取当前数据库的所有对象的架构信息。
相比SubSonic 2.2中获取数据库对象详细信息,SQL Doc要详细和准确一些,经我的测试,对于字段描述信息,如果删除某个表的字段,SubSonic的方式获取字段描述信息有可能会出现错位的情况,下面是SubSonic中的获取数据库表详细信息的SQL:
SubSonic Code
SELECT
TABLE_CATALOG AS [Database],
TABLE_SCHEMA AS Owner,
TABLE_NAME AS TableName,
COLUMN_NAME AS ColumnName,
ORDINAL_POSITION AS OrdinalPosition,
COLUMN_DEFAULT AS DefaultSetting,
IS_NULLABLE AS IsNullable, DATA_TYPE AS DataType,
CHARACTER_MAXIMUM_LENGTH AS MaxLength,
DATETIME_PRECISION AS DatePrecision,
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsIdentity') AS IsIdentity,
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsComputed') as IsComputed,
properties.value as ColumnDescription
FROM INFORMATION_SCHEMA.COLUMNS
left join sys.extended_properties properties
ON object_Id(columns.Table_Name) = properties.major_id --AND columns.COLLATION_SCHEMA
AND columns.Ordinal_position = properties.minor_id AND class_desc='OBJECT_OR_COLUMN'
WHERE TABLE_NAME='schools'
ORDER BY OrdinalPosition ASC
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››获取checkedListBox 选中的项并且移动
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接