判断视图是都存在
IF object_id(
'viewname'
)
IS
not
NULL
begin
--操作
--drop view viewname
end
GO
判断表是否存在
IF object_id(
'tablename'
)
IS
NULL
BEGIN
--操作
END
GO
判断列是否存在
IF
NOT
EXISTS (
SELECT
1
FROM
dbo.syscolumns
WHERE
[
name
]=
'columnname'
AND
id=object_id(
'tablename'
))
begin
--操作
end
go
判断函数是都存在
IF exists (
select
1
from
sysobjects
where
xtype=
'fn'
and
name
=
'funcname'
)
BEGIN
--drop function funcname
END
判断存储过程是否存在
IF exists (
select
1
from
sysobjects
where
xtype=
'p'
and
name
=
'procname'
)
BEGIN
--drop proc procname
end
判断触发器是存在
IF exists (
select
*
from
sysobjects
where
id=object_id(N
'tr_es_Order_upd'
)
and
objectproperty(id,N
'IsTrigger'
)=1)
begin
DROP
TRIGGER
tr_es_Order_upd ;
end
go
创建索引
IF
NOT
EXISTS (
select
1
from
sys.indexes
where
name
=
'index_cb_WarehouseInOutDtl_MaterialsGUID'
)
begin
CREATE
INDEX
index_cb_WarehouseInOutDtl_MaterialsGUID
ON
cb_WarehouseInOutDtl (MaterialsGUID)
END
GO
转载自:公司知识库,作者:吴东