zoukankan      html  css  js  c++  java
  • 读取SQLServer2005的系统数据 荣

    取得数据库中的表信息:
    SELECT Script = CASE WHEN ep.[Value] IS NULL THEN oj.Name ELSE ep.[Value]  END, oj.Name AS TableName, oj.id AS id, oj.crdate AS createDate, oj.type AS tableType FROM sys.sysobjects oj LEFT JOIN sys.extended_properties ep ON ep.major_id = oj.id AND ep.minor_id = 0 ORDER BY oj.id

    取得数据库中所有列信息的SQL语句:

    SELECT oj.Name AS TableName, cl.Name AS ColumnName,tp.Name AS ColumnType, tp.xtype AS ColumnTypeIndex, cl.length, cl.xscale AS decimaldigits, Script = CASE WHEN ep.[Value] IS Null THEN cl.Name ELSE ep.[Value] END, DefaultValue = CASE WHEN cm.text IS NULL THEN '' WHEN cm.text = '(getdate())' THEN '当前日期' ELSE cm.text END, cl.isnullable, cl.colstat AS IsMarking, cl.id, cl.colid FROM sys.syscolumns cl LEFT JOIN sys.sysobjects oj ON oj.id = cl.id LEFT JOIN sys.systypes tp ON cl.xtype = tp.xtype LEFT JOIN sys.syscomments cm ON cm.id=cl.cdefault LEFT JOIN sys.extended_properties ep ON ep.major_id = cl.id AND ep.minor_id = cl.colid WHERE oj.type='U' AND tp.Name != 'sysname' ORDER BY oj.id, cl.colid

    取得数据库中的外键信息:
    SELECT OBJECT_NAME(fk.constid) AS FKName, fk.constid AS FKID, OBJECT_NAME(fk.fkeyid) AS TableName, fk.fkeyid AS TableID, cl.name AS ColumnName, RCol.name AS RColumnName, OBJECT_NAME(fk.rkeyid) AS ParentTableName, fk.rkeyid AS ParentTableID FROM sys.sysobjects oj INNER JOIN sys.sysforeignkeys fk ON oj.xtype = 'F' AND oj.id = fk.constid INNER JOIN sys.syscolumns cl ON fk.fkeyid = cl.id INNER JOIN sys.syscolumns RCol ON fk.rkeyid = RCol.id AND fk.fkey = cl.colid AND fk.rkey = RCol.colid


    取得数据库表的主键信息:
    存储过程:sp_pkeys  参数@table_name
  • 相关阅读:
    springboot scheduled多线程
    Oracle sql 小数点前面0不显示
    (转)VIM常用命令集锦
    java 面试题
    关于oracle start with connect by 全表扫描的一点想法
    (转)window.opener方法的使用 刷新父页面
    (转)jQuery “not readonly” selector
    (转)jquery合并单元格
    Java 格式化json为json树
    我的2018
  • 原文地址:https://www.cnblogs.com/admin11/p/878298.html
Copyright © 2011-2022 走看看