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

  • 相关阅读:
    [Tips]:SQL server 2005 Create Assembly Failed
    [Tips]:JavaScript命名空间
    卓有成效的程序员之笔记与实践
    Culture List
    Windows Azure CloudBlobContainer.CreateIfNotExist : One of the request inputs is out of range.
    Failed to add FS to collection at ResourceService.SetResource in Map 3D 2013
    ADO.net DataTable 和Amazon SimpleDB的相互转换
    对MapGuide/AIMS进行压力测试StressTest并进行性能优化
    AIMS/MapGuide API二次开发从入门到精通视频课程系列3
    创建Visual Studio项目模版向导的几篇参考文章
  • 原文地址:https://www.cnblogs.com/wintersun/p/1812103.html
Copyright © 2011-2022 走看看