sqlserver採集欄位的sql語句
SELECT CAST
( o.name AS VARCHAR ( 1000 ) ) AS TABLE_NAME,
CAST ( c.name AS VARCHAR ( 100 ) ) AS COLUMN_NAME,
c.column_id AS ORDINAL_POSITION,
c.PRECISION AS DECIMAL_PRECISION,
c.SCALE AS NUMERIC_SCALE,
SCHEMA_NAME( o.schema_id ) AS TABLE_SCHEMA,
c.system_type_id AS SQL_DATA_TYPE,
c.user_type_id ,
CAST ( TYPE_NAME( c.user_type_id ) AS VARCHAR ( 100 ) ) AS DATA_TYPE,
case when c.IS_NULLABLE=0 then 'No' else 'Yes' end as IS_NULLABLE ,
CASE
WHEN ( c.user_type_id>= 40 AND c.user_type_id<= 62 )
OR c.user_type_id= 104
OR c.user_type_id= 127
OR c.user_type_id= 173 THEN
NULL ELSE
CASE
WHEN c.PRECISION = 0 THEN
NULL ELSE c.PRECISION
END
END AS NUMERIC_PRECISION,
CASE
WHEN c.user_type_id= 231
OR c.user_type_id= 239 THEN
c.max_length / 2
WHEN ( c.user_type_id>= 40 AND c.user_type_id<= 62 )
OR c.user_type_id= 104
OR c.user_type_id= 127
OR c.user_type_id= 173 THEN
NULL ELSE c.max_length
END AS CHARACTER_MAXIMUM_LENGTH,
CAST ( d.definition AS VARCHAR ( 1000 ) ) AS COLUMN_DEFAULT,
CAST ( p.value AS VARCHAR ( 1000 ) ) AS COMMENTS
FROM
sys.columns AS c
INNER JOIN sys.tables AS o ON c.object_id = o.object_id
LEFT OUTER JOIN [sys].[default_constraints] AS d ON d.object_id = c.default_object_id
LEFT OUTER JOIN [sys].[extended_properties] AS p ON c.object_id = p.major_id
AND c.column_id= p.minor_id
AND p.name IN ( 'comment', 'MS_Description' )
WHERE
o.schema_id = SCHEMA_ID( 'DBO' ) UNION ALL
SELECT CAST
( o.name AS VARCHAR ( 1000 ) ) AS TABLE_NAME,
CAST ( c.name AS VARCHAR ( 100 ) ) AS COLUMN_NAME,
c.column_id AS ORDINAL_POSITION,
c.PRECISION AS DECIMAL_PRECISION,
c.SCALE AS NUMERIC_SCALE,
SCHEMA_NAME( o.schema_id ) AS TABLE_SCHEMA,
c.system_type_id AS SQL_DATA_TYPE,
c.user_type_id ,
CAST ( TYPE_NAME( c.user_type_id ) AS VARCHAR ( 100 ) ) AS DATA_TYPE,
case when c.IS_NULLABLE=0 then 'No' else 'Yes' end as IS_NULLABLE ,
CASE
WHEN ( c.user_type_id>= 40 AND c.user_type_id<= 62 )
OR c.user_type_id= 104
OR c.user_type_id= 127
OR c.user_type_id= 173 THEN
NULL ELSE
CASE
WHEN c.PRECISION = 0 THEN
NULL ELSE c.PRECISION
END
END AS NUMERIC_PRECISION,
CASE
WHEN c.user_type_id= 231
OR c.user_type_id= 239 THEN
c.max_length / 2
WHEN ( c.user_type_id>= 40 AND c.user_type_id<= 62 )
OR c.user_type_id= 104
OR c.user_type_id= 127
OR c.user_type_id= 173 THEN
NULL ELSE c.max_length
END AS CHARACTER_MAXIMUM_LENGTH,
CAST ( d.definition AS VARCHAR ( 1000 ) ) AS COLUMN_DEFAULT,
CAST ( p.value AS VARCHAR ( 1000 ) ) AS COMMENTS
FROM
sys.columns AS c
INNER JOIN sys.views AS o ON c.object_id = o.object_id
LEFT OUTER JOIN [sys].[default_constraints] AS d ON d.object_id = c.default_object_id
LEFT OUTER JOIN [sys].[extended_properties] AS p ON c.object_id = p.major_id
AND c.column_id= p.minor_id
AND p.name IN ( 'comment', 'MS_Description' )
WHERE
o.schema_id = SCHEMA_ID( 'DBO' )
相關文章
- sql語句修改欄位型別和增加欄位SQL型別
- 用SQL語句增加刪除修改欄位SQL
- 通用SQL語句修改欄位預設值SQL
- sqlserver dba常用的sql語句SQLServer
- 帝國CMS 批次修改欄位內容sql語句SQL
- SQL Server中獲取資料庫名、表名、欄位名和欄位註釋的SQL語句SQLServer資料庫
- SQL Server語句刪除帶有預設值的欄位SQLServer
- SQLServer資料庫管理的常用SQL語句SQLServer資料庫
- PL/SQL Developer中輸入SQL語句時如何自動提示欄位SQLDeveloper
- SQL SERVER 資料庫查詢表和欄位資訊語句SQLServer資料庫
- sqlserver 檢視和sql語句的效率對比SQLServer
- [Mysql 查詢語句]——查詢欄位MySql
- 利用 alter 語句修改欄位屬性
- SQLServer資料庫管理常用的SQL和T-SQL語句SQLServer資料庫
- SQLServer效能優化之改寫SQL語句SQLServer優化
- sqlserver資料庫 去除欄位中空格,換行符,回車符(使用replace語句)SQLServer資料庫
- 利用SQL語句完成位操作 (轉)SQL
- 【SQL】16 SQL CREATE INDEX 語句、 撤銷索引、撤銷表以及撤銷資料庫、ALTER TABLE 語句、AUTO INCREMENT 欄位SQLIndex索引資料庫REM
- mysql 用sql語句查詢一個表中的所有欄位型別、註釋MySql型別
- 【原】獲取SQLServer的最完整資料字典的SQL語句SQLServer
- 如何自動填充SQL語句中的公共欄位SQL
- (轉)隨機選擇行的SQL語句? ORACLE SQLSERVER ECT.隨機SQLOracleServer
- SQL INSERT INTO 語句詳解:插入新記錄、多行插入和自增欄位SQL
- 常用Sqlserver中的查詢語句SQLServer
- 多個值以,分隔儲存在一個欄位精確匹配查詢 sql語句SQL
- SQLServer SYSPROCESSES表欄位解說明SQLServer
- sqlserver查詢一個庫所有表的欄位名及欄位型別SQLServer型別
- Sqlserver修改線上表的表欄位型別SQLServer型別
- 批次修改欄位字符集和表表字符集,sql生成SQL
- [2020528]寫sql語句不要忘記給欄位加上表別名.txtSQL
- SQL語句SQL
- SQL語句IN的用法SQL
- 常用的SQL語句SQL
- 常用的SQL 語句SQL
- SQL 語句 as 的用法SQL
- oracle的sql語句OracleSQL
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- SQL新增表欄位SQL