程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase教程 >> 獲取數據庫所有列以及列的類型是否為空是否為默認值是否為主鍵

獲取數據庫所有列以及列的類型是否為空是否為默認值是否為主鍵

編輯:SyBase教程

獲取數據庫所有列以及列的類型是否為空是否為默認值是否為主鍵


通過各種查資料,並且閱讀sqlserver自帶的存儲過程總結出來的

SELECT DISTINCT c.name AS tablename, a.name,a.is_nullable,dbo.GetRemoveParentheses(d.text) AS defaultvalue,
		CASE WHEN (a.name = index_col (c.name, f.index_id,  1) or
         a.name = index_col (c.name, f.index_id,  2) or
         a.name = index_col (c.name, f.index_id,  3) or
         a.name = index_col (c.name, f.index_id,  4) or
         a.name = index_col (c.name, f.index_id,  5) or
         a.name = index_col (c.name, f.index_id,  6) or
         a.name = index_col (c.name, f.index_id,  7) or
         a.name = index_col (c.name, f.index_id,  8) or
         a.name = index_col (c.name, f.index_id,  9) or
         a.name = index_col (c.name, f.index_id, 10) or
         a.name = index_col (c.name, f.index_id, 11) or
         a.name = index_col (c.name, f.index_id, 12) or
         a.name = index_col (c.name, f.index_id, 13) or
         a.name = index_col (c.name, f.index_id, 14) or
         a.name = index_col (c.name, f.index_id, 15) or
         a.name = index_col (c.name, f.index_id, 16))
		 THEN
		 1
		 ELSE
		 0
		 END
		 AS isPrimary
		 ,
        CASE a.precision
          WHEN 0
          THEN CASE a.is_ansi_padded
                 WHEN 1
                 THEN CONVERT(NVARCHAR(15), b.name + '('
                      + CONVERT(NVARCHAR(10), a.max_length) + ')')
                 WHEN 0 THEN b.name
               END
          ELSE CASE a.scale
                 WHEN 0 THEN b.name
                 ELSE b.name + '(' + CONVERT(NVARCHAR(10), a.precision) + ','
                      + CONVERT(NVARCHAR(10), a.scale) + ')'
               END
        END AS typelength 
FROM  sys.columns a
        LEFT JOIN sys.types b ON a.system_type_id = b.system_type_id
                                 AND a.user_type_id = b.user_type_id
		INNER JOIN sysobjects c ON c.id = a.object_id
		LEFT JOIN syscomments d ON d.id = a.default_object_id
		INNER JOIN sys.key_constraints e ON e.parent_object_id = a.object_id
		INNER JOIN sys.indexes f ON e.unique_index_id = f.index_id

WHERE c.xtype = 'u' AND f.is_primary_key = 1  


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved