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

    表中结构如下图

  • 相关阅读:
    Http请求头与响应头
    获取ip位置方法
    简单的Http Server实现
    HTTP
    long、int与byte数组之间的相互转换
    GlusterFS简单配置
    创建线程池
    网络编程socket
    面向对象-进阶篇
    面向对象-初级篇
  • 原文地址:https://www.cnblogs.com/SoftWareIe/p/9472726.html
Copyright © 2011-2022 走看看