数据库中表,函数,存储过程,触发器不重复创建格式
2012-11-07 11:10
501 查看
--一视图一
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 '
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 '
相关文章推荐
- SQL Server ->> 重新创建Assembly和自动重建相关的数据库编程对象(存储过程,函数和触发器)
- 数据库中存储过程、函数、触发器的区别
- mysql 触发器采坑记录(mysql 触发器采坑记录 由于不了解mysql创建触发器要记录创建者IP,导致更改创建者IP后,触发器不可执行。 当创建触发器(视图、存储过程、函数)时,如果没有)
- mysql存储过程、函数和触发器的创建
- 数据库存储过程、函数、触发器的区别
- 3.22 学数据库 视图 存储过程 触发器 事务 函数 索引
- MySQL 之 视图、触发器、存储过程、函数、事物与数据库锁
- 查询SQLServer2005中某个数据库中的表结构、索引、视图、存储过程、触发器以及自定义函数
- 数据库可编程性;存储过程;函数;触发器
- 数据库的几个问题存储过程触发器函数创建以及sql优化
- MySQL只导出数据库结构和存储过程、触发器、函数,但不导表数据
- mysql存储过程、函数和触发器的创建 [转]
- mysql 查看数据库中的存储过程,表,函数,以及创建的源码
- 数据库中的表结构、索引、视图、存储过程、触发器以及自定义函数
- 【数据库学习笔记】MySQL_03_存储过程,触发器,权限,视图,函数
- 【数据库学习笔记】Oracle_04_存储过程,函数,触发器,索引,同义词
- mysql一些复制表、增删改索引、建存储过程、创建函数、创建触发器的一些命令
- Oracle中如何导出存储过程、函数、包和触发器的定义语句?如何导出表的结构?如何导出索引的创建语句?
- 数据库存储过程,触发器,游标,函数