• 关于Ms Sql server 表列等是否存在


    select object_id('名称') ,object_id('名称','类型')

    1. 等价于 

    select * from sys.objects where name ='名称'
    select * from sys.objects where name ='名称' and type ='类型'

    2. 可用于判断表等是否存在

    如:

    if(OBJECT_ID('rdrecord','u') is not null)
    print '存在'
    else
    print '不存在'

    3. 可返回sys.objects系统视图中的object_id的值 如果没有则返回null


    4. sys.objects里有所有的数据库对像 如:表、视图、列、存储过程、函数、约束等等等等


    5. 视了试图、表、存储过程类型明确的可用 object_id('名称','类型')判断。当然sql2008r2(以前版本未测试)一个数据库中的对像名是不能重复的所以也可只用对像名判断

    别的类型可用类似方法

    select * from sys.objects where object_id =object_id(N'DF__rdrecord__Sex__07020F21') and parent_object_id=object_id('表名','类型')
    select COL_LENGTH('','');--列的长度 判断列是否存在

    6. 类型如下

    V = View
    U = Table (user-defined)
    P = SQL Stored Procedure


    AF = Aggregate function (CLR)
    C = CHECK constraint
    D = DEFAULT (constraint or stand-alone)
    F = FOREIGN KEY constraint
    FN = SQL scalar function
    FS = Assembly (CLR) scalar-function
    FT = Assembly (CLR) table-valued function
    IF = SQL inline table-valued function
    IT = Internal table
    PC = Assembly (CLR) stored-procedure
    PG = Plan guide
    PK = PRIMARY KEY constraint
    R = Rule (old-style, stand-alone)
    RF = Replication-filter-procedure
    S = System base table
    SN = Synonym
    SQ = Service queue
    TA = Assembly (CLR) DML trigger
    TF = SQL table-valued-function
    TR = SQL DML trigger
    UQ = UNIQUE constraint
    X = Extended stored procedure

    表中结构如下图

  • 相关阅读:
    Objective-C多线程-02
    Objective-C多线程-01
    Objective-C的属性与实例变量
    KVO的内部实现原理
    ASIHTTPRequest 和 AFNetWorking 的比较
    Python类和函数_规划式开发
    禁用密码登录,改用key秘钥对登录
    Python类和函数_时间与纯函数
    Python类和对象_调试与术语
    Python类和对象_修改和复制
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/9472726.html
Copyright © 2020-2023  润新知