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型別
- sqlserver dba常用的sql語句SQLServer
- 帝國CMS 批次修改欄位內容sql語句SQL
- SQL Server中獲取資料庫名、表名、欄位名和欄位註釋的SQL語句SQLServer資料庫
- [2020528]寫sql語句不要忘記給欄位加上表別名.txtSQL
- 【SQL】16 SQL CREATE INDEX 語句、 撤銷索引、撤銷表以及撤銷資料庫、ALTER TABLE 語句、AUTO INCREMENT 欄位SQLIndex索引資料庫REM
- SQL INSERT INTO 語句詳解:插入新記錄、多行插入和自增欄位SQL
- 如何自動填充SQL語句中的公共欄位SQL
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- SQL語句SQL
- SQL語句IN的用法SQL
- SQLServer2012刪除表欄位SQLServer
- 批次修改欄位字符集和表表字符集,sql生成SQL
- Sqlserver定位哪些物件和哪些會話哪些sql語句消耗了tempdbSQLServer物件會話
- 【SQL】9 SQL INSERT INTO 語句SQL
- 【SQL】10 SQL UPDATE 語句SQL
- 【SQL】11 SQL DELETE 語句SQLdelete
- SQL SELECT 語句SQL
- sql常用語句SQL
- T-SQL運維指令碼——檢視SQLServer平均最耗資源時間的SQL語句SQL運維指令碼Server
- MySQL中join語句的基本使用教程及其欄位對效能的影響MySql
- sql語句如何執行的SQL
- MySQL中常用的SQL語句MySql
- SQL 語句的注意事項SQL
- sql宣告變數,及if -else語句、while語句的用法SQL變數While
- 1.3. SQL 語句SQL
- Oracle基本SQL語句OracleSQL
- Sql語句小整理SQL
- SQL語句優化SQL優化
- SQL 語句學習SQL
- 資料庫常用的sql語句大全--sql資料庫SQL
- 獲取SqlServer 2005中欄位的備註資訊SQLServer
- SQLServer中如何刪除欄位的自增標識SQLServer
- Sqlserver的merge into或delete語句堵塞select語句,鎖型別是LCK_M_ISSQLServerdelete型別
- SQLSERVER 語句交錯引發的死鎖研究SQLServer
- SqlServer中迴圈和條件語句SQLServer
- 在oracle中,select語句查詢欄位中非純數字值Oracle
- Oracle SQL精妙SQL語句講解OracleSQL