zoukankan      html  css  js  c++  java
  • 创建数据库、表、存储过程...前的判断

    -创建数据库
    if exists(select * from sysdatabases where name=N'master..test')
    drop database test
    create database test


    --创建存储过程(法1)
    if exists(select * from sysobjects where name=N'proc_name' and type='p')
    drop proc proc_name
    create proc proc_name
    as
    select * from table_name

    --创建存储过程(法2)
    if exists (select * from sysobjects where id=object_id(N'dbo.proc_name'and objectproperty(id,N'isprocedure')=1--id是当前数据库中某个对象(表、存储过程.)的ID
    --
    or:if exists (select * from sysobjects where and objectproperty(object_id(N'dbo.proc_name'),N'isprocedure')=1)
    drop proc proc_name 
    create proc proc_name
    as 
    select * from table_name




    --创建表(法1)
    if exists(select * from sysobjects where name=N'table_name')
    drop table table_name
    create table table_name
    (
       _id 
    int,
       _name 
    char(10)
    )
    insert into table_name select 1,'zhang' union all
                       
    select 2,'zhu'   union all
                          
    select 3,'liuchunmei'  

    --创建表(法2)
    if exists(select * from sysobjects where id=object_id(N'table_name'and objectproperty(id,N'istable')=1)
    --or:if exists(select * from sysobjects where objectproperty(object_id(N'table_name'),N'istable')=1)
    drop table table_name
    create table table_name
    (
       _id 
    int,
       _name 
    char(10)
    )
    insert into table_name select 1,'zhang' union all
                       
    select 2,'zhu'   union all
                          
    select 3,'liuchunmei'




    OBJECTPROPERTY
    返回当前数据库中对象的有关信息。

    语法
    OBJECTPROPERTY ( id , property )

    参数
        id
        一个表达式,包含当前数据库中某个对象(表、存储过程…)的 ID。id 的数据类型是 int。

        Property

        一个表达式,包含针对由 id 指定的对象将要返回的信息。Property 可以是下面这些值中的一个。

        说明:除非加以注释,否则,如果 property 是无效的属性名,则返回 NULL。
       
        具体property属性请参考SQL Server 联机丛书

  • 相关阅读:
    HTML <button> 标签
    git帮助命令
    PHP从数组中删除元素的方法
    thinkphp里面的or查询
    登录操作中的记住密码操作的算法逻辑
    重复密码需一致的表单实例
    判断 checkbox 是否选中以及 设置checkbox选中
    update和saveOrUpdate具体解释
    gopkg:一种方便的go pakcage管理方式
    一次正确选择,改变一生命运!
  • 原文地址:https://www.cnblogs.com/perfect/p/567409.html
Copyright © 2011-2022 走看看