zoukankan      html  css  js  c++  java
  • 数据库中表,函数,存储过程,触发器不重复创建格式

    --一视图一
    if exists(select 1 from sysobjects where name=N'v_ExpenseQry' and type=N'V')
    drop view v_ExpenseQry
    go

    create view v_ExpenseQry
    with encryption
    as

    --一视图二
    if exists (select TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
    WHERE TABLE_NAME = 'v_ExpenseQry')
    DROP VIEW v_ExpenseQry
    GO


    create view v_ExpenseQry
    with encryption
    as


    --函数
    if exists (select 1 from sysobjects where name =N'fn_pordersearch' and type in (N'Fn',N'IF',N'TF'))
    drop function fn_pordersearch
    go

    create function fn_pordersearch()
    returns table

    WITH ENCRYPTION

    as
    return

    --存储过程
    if exists (select 1 from sysobjects where name=N'pd_InsertsaleAmountAccrualItem' and type=N'P')
    drop procedure pd_InsertsaleAmountAccrualItem
    go

    create procedure pd_InsertsaleAmountAccrualItem(@transferid integer,@amount money,@sodid int,@transerdate datetime='2000-01-01',@istxamount bit=false,@op_id varchar(20))
    with encryption
    as

    ---触发器
    if exists (select * from sysobjects where id = object_id(N'[Tr_deptTran_Ins]') and OBJECTPROPERTY(id, N'IsTRIGGER') = 1)
    Drop Trigger Tr_deptTran_Ins
    go


    CREAte trigger Tr_deptTran_Ins on deptTran
    with encryption
    for insert
    as

    --创建表格


    if exists (select 1
    from sysobjects
    where id = object_id('StorageAgreement')
    and type = 'U')
    drop table StorageAgreement
    go


    /*==============================================================*/
    /* Table: StorageAgreement */
    /*==============================================================*/
    create table StorageAgreement (
    UID numeric(10) not null, ---主键
    StoreID varchar(12) null, ---仓库
    AgreementNo varchar(30) null, ---协议号
    StorageLocation varchar(50) null, ---存放地
    SigningDate datetime null, ---签订日期
    ValidityDate datetime null, ---有效期
    operator Varchar(20) null, ---操作员
    inputdate datetime null, ---输入日期
    constraint PK_STORAGEAGREEMENT primary key (UID)
    )
    go

    查询表相关的触发器启用情况:

    select 表名=object_name(parent_obj),触发器名=name
    ,状态=case status & power(2,11) when power(2,11) then '禁用 ' else '启用 ' end
    from sysobjects
    where type= 'TR '

  • 相关阅读:
    强迫症
    bzoj1758 [Wc2010]重建计划
    bzoj1070 [SCOI2007]修车
    bzoj3675 [Apio2014]序列分割
    bzoj1010 [HNOI2008]玩具装箱toy
    bzoj3697 采药人的路径
    bzoj2152 聪聪可可
    bzoj2599 [IOI2011]Race
    Ubuntu 18.04 LTS 下 GTK3 安装与编译
    启动或重启 dnsmasq 提示端口 53 被占用的解决方案
  • 原文地址:https://www.cnblogs.com/annabook/p/2758422.html
Copyright © 2011-2022 走看看