zoukankan      html  css  js  c++  java
  • object_id用法

    特别是在建表建存储过程的时候进场会写到:
    
    IF OBJECT_ID('Table_Test','U') IS NOT NULL
    DROP TABLE Table_Test
    这种方式代替了以往所使用的
    
    IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME = 'Table_Test')
    DROP TABLE Table_Test
    第一段代码中的 U 可以省略不写, 这样系统就会检索所有的对象名称以找到对应的ID, 但是写出来就可以更加明确是哪一种类型,筛选的范围要小很多.
    以下列出全部 Object type (加粗的是比较常用的): 
    
    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
    
    P = SQL Stored Procedure
    
    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
    
    TT = Table type
    
    U = Table (user-defined)
    
    UQ = UNIQUE constraint
    
    V = View
    
    X = Extended stored procedure
    
    可以通过这个查询语句获取当前数据库中各个数据库表,视图,存储过程等数量。
    
    SELECT CASE TYPE
                   WHEN 'U'  THEN 'User Defined Tables'
                   WHEN 'V'  THEN 'View' 
                  WHEN 'S'  THEN 'System Tables'
                   WHEN 'IT' THEN 'Internal Tables'
                   WHEN 'P'  THEN 'Stored Procedures'
                   WHEN 'PC' THEN 'CLR Stored Procedures'
                   WHEN 'X'  THEN 'Extended Stored Procedures'
                   WHEN 'FN' THEN 'Scalar-valued Functions'
                   WHEN 'IF' THEN 'Table-valued Functions'
            END AS Objects,
            COUNT(*) AS Counts   
    FROM SYS.OBJECTS
    WHERE TYPE IN ('U','V','S','IT','P','PC','X','FN','IF')
    GROUP BY TYPE
    

      

  • 相关阅读:
    CentOS ping www.baidu.com 报错 name or service not know
    python2 当中 遇到 UnicodeDecodeError UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 37: ordinal not in range(128)
    shell基本语法
    android---笔记 AppContext extends Application
    android笔记--加载框
    android笔记--与服务器交互更改简历状态
    android笔记---AndroidManifest.xml
    android笔记-----消息提示
    ios笔记一 追加数据
    android笔记一 控件属性
  • 原文地址:https://www.cnblogs.com/ilrc/p/5211302.html
Copyright © 2011-2022 走看看