zoukankan      html  css  js  c++  java
  • SqlServer中使用Tsql找出identity列

          有没有方法找出DataBase中所有表的Identity列?可以的,有下面几种T-SQL可以实现:
    第一种方法:使用columnproperty函数:

    select 
        table_name,column_name 
    from 
        information_schema.columns
    where 
        columnproperty(object_id(table_name),column_name,'isidentity')=1
    order by table_name

    第二种方法:使用sys.all_columns视图:

    select 
        object_name(object_id),name 
    from 
        sys.all_columns 
    where 
        is_identity=1  and objectproperty(object_id,'isusertable')=1

    第三种方法:使用identity_columns视图:

    select 
        object_name(object_id),name 
    from 
        sys.identity_columns 
    where 
        objectproperty(object_id,'isusertable')=1

    希望这篇POST对您有帮助! 


    作者:Petter Liu
    出处:http://www.cnblogs.com/wintersun/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    该文章也同时发布在我的独立博客中-Petter Liu Blog

  • 相关阅读:
    不错的计算机免费电子书网站
    十点提高编程技巧
    delphi 通过TStyleManager设置主题类型
    delphi 简体和繁体字符串转换
    delphi unidac 连接mysql
    Delphi 的字符及字符串 string、AnsiString、WideString、String[n]、ShortString
    delphi format格式
    AnsiString和WideString 区别
    企业级Docker私有仓库部署(https)
    企业级Docker私有仓库之Harbor部署(http)
  • 原文地址:https://www.cnblogs.com/wintersun/p/1812103.html
Copyright © 2011-2022 走看看