zoukankan      html  css  js  c++  java
  • 关于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

    表中结构如下图

  • 相关阅读:
    关于 拼接 url 连接 参数的问题(爬虫)。
    date 时间确定
    JavaScript跨域解决方法大全
    JS的 try catch使用心得
    博客要搬家啦!
    bzoj 3676: [Apio2014]回文串 -- 回文自动机
    bzoj 2631: tree -- LCT
    bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 -- LCT
    bzoj 2648: SJY摆棋子&&2716: [Violet 3]天使玩偶 --kdtree
    bzoj 1978: [BeiJing2010]取数游戏 game -- dp
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/9472726.html
Copyright © 2011-2022 走看看