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 '

  • 相关阅读:
    python之matplotlib库中pyplot的基本使用(python数据分析之绘制图形)
    小球称重问题~通过三次称重找出十二个小球质量不一样的小球,并判断小球轻重
    python爬虫—爬取英文名以及正则表达式的介绍
    Python爬取酷狗飙升榜前十首(100)首,写入CSV文件
    Requests库主要方法解析以及Requests库入门需要掌握的框架
    彻底理解Java中的21种锁!
    JavaIO流常见面试题
    Linux常用命令
    语言学习网
    类加载器的命名空间
  • 原文地址:https://www.cnblogs.com/annabook/p/2758422.html
Copyright © 2011-2022 走看看