drop table [表名] if exists (select * from sysobjects where id = object_id(N’[表名]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1) drop table [表名] 3 判断存储过程是否存在 Sql代码 if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY...
drop table [表名] if exists (select * from sysobjects where id = object_id(N’[表名]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1) drop table [表名] 3 判断存储过程是否存在 Sql代码 if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY...
if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1) drop procedure [存储过程名] if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1) drop ...
if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1) drop procedure [存储过程名] if exists (select * from sysobjects where id = object_id(N’[存储过程名]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1) drop ...
if object_id(’tempdb..#临时表名’) is not null drop table #临时表名 if object_id(’tempdb..#临时表名’) is not null drop table #临时表名 5 判断视图是否存在 Sql代码 --SQL Server 2000 IF EXISTS (SELECT * FROM sysviews WHERE object_id = ’[dbo].[视图名]’ ...
drop function [dbo].[函数名] 7 获取用户创建的对象信息 SELECT [name],[id],crdate FROM sysobjects where xtype='U' 8 判断列是否存在 if exists(select * from syscolumns where id=object_id('表名') and name='列名') alter table 表名 drop column 列名 ...
DROPobject_typeIFEXISTSobject_name 能够用于DROP的object_type,如Tables, Database, Function, Trigger, Stored Procedure, Column, User, Type, View, Schema,皆可套用,比如:ALTER TABLE PERSONDROP COLUMN If EXISTS NAME SQL Server 2016新特性:DROP IF EXISTS 标签:basesysges.netschfunctionname...
_locksWHEREresource_database_id=DB_ID()ANDresource_type='OBJECT'ANDresource_associated_entity_id=OBJECT_ID('MyTable'))BEGIN-- 删除字段ALTERTABLEMyTableDROPCOLUMNMyColumn;-- 检查字段是否成功删除IFNOTEXISTS(SELECT*FROMsys.columnsWHEREobject_id=OBJECT_ID('MyTable')ANDname='MyColumn')BEGINPRINT'...
我们知道,在Oracle中,不管你带不带默认值,删除字段就是alter table ... drop column ...,为什么到了SQL Server,有其他的讲究? 原来这个SQL Server的字段,不是普通定义的表字段,而是通过这几个操作定义的。 1. 创建一个默认值对象, ifnotexists(select1f...
原来这个SQL Server的字段,不是普通定义的表字段,而是通过这几个操作定义的。 1. 创建一个默认值对象, 代码语言:javascript 复制 ifnotexists(select1from sys.sysobjects where uid=schema_id(schema_name())and name like'chardt'and xtype='D')exec sp_executesqlN'create default [chardt] as ''' 2....