V = 视图 X = 扩展存储过程*/--数据库IFexists(SELECT1fromsys. sysdatabaseswherename=dbname)begindropdatabasedbnameend--表IFexists(SELECT1fromsys. sysobjectswhereid=object_id(N'tbname')ANDOBJECTPROPERTY(id, N'IsUserTable')=1)BEGINdropTABLEtbnameEND--存储过程IFexists(SELECT1fromsys. sysobjectsw...
USEmasterGOIFEXISTS(SELECT*FROMsysdatabasesWHEREname='people')DROPDATABASEpeople 注:EXISTS(查询语句)用来检测某个查询是否存在。 二、创建和删除表 1、创建表的语法如下: CREATETABLE表名 ( 字段1 数据类型 列的特征, 字段2 数据类型 列的特征, ... ) 示例: 需求:创建学员信息表peoInfo。 USEpeopleGOCREA...
代码如下: --账号表ifexists(select*fromsysobjectswherename='Account')droptableAccountgocreatetableAccount(AccountIdintidentity(10001,1)primarykey,--账号编号AccountNamevarchar(20)notnull,--账号名称AccountContentnvarchar(500)notnull,--账号简介originalityintnotnull,--原创数TypeIdintreferencesAccountType(TypeId...
Use tempDB IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo]. 05 [ProductNew]') AND type in (N'U')) DROP TABLE [dbo].[ProductNew] -- STEP 2: 建立訂單資料表 06 CREATE TABLE dbo.ProductNew( ProductID int primary key, FilmName nvarchar(30), direct nvarcha...
if exists(select * from sysobjects where name='Teacher') drop table Teacher go create table Teacher ( -- TeacherId int primary key, --讲师编号,主键 TeacherId int identity(100,1) primary key,--自增主键用identity(基数,增量) LoginAccount varchar(50) not null,--登录帐号 ...
@description = 'CreateTableTest'; -- Add job step for create table EXEC jobs.sp_add_jobstep @job_name = 'CreateTableTest', @command = N'IFNOTEXISTS(SELECT*FROMsys.tablesWHEREobject_id = object_id(''Test''))CREATETABLE[dbo].[Test]([TestId] [int]NOTNULL);', @target_group_name =...
-- Switch to the database migration that is already restored for MIusemigration; go--Check if the restored table test exist and contain a rowselect*fromtest; go-- Check that the SQL on-premises Windows user/group existsselect*fromsys.database_principals; go-- the ...
DROP TABLE IF EXISTS [dbo].[fact_sale]; --Create the fact_sale table. CREATE TABLE [dbo].[fact_sale] ( [SaleKey] [bigint] NULL, [CityKey] [int] NULL, [CustomerKey] [int] NULL, [BillToCustomerKey] [int] NULL, [StockItemKey] [int] NULL, [InvoiceDateKey] [datetime2](6) ...
GOIFEXISTS(SELECT*FROMsys.objectsWHEREobject_id=OBJECT_ID(N'[dbo].[ufn_AuditReport]')ANDtypein(N'FN',N'IF',N'TF',N'FS',N'FT'))DROPFUNCTION[dbo].[ufn_AuditReport]GOCREATEFUNCTIONdbo.ufn_AuditReport(@filepathvarchar(1000))RETURNS@retAuditReportTABLE([session_id]intNULL,[server_principa...
IF EXISTS(SELECT*FROMsys.objectsWHEREobject_id=OBJECT_ID(N'[dbo].[ufn_AuditReport]')ANDtypein(N'FN',N'IF',N'TF',N'FS',N'FT')) DROPFUNCTION[dbo].[ufn_AuditReport] GO CREATEFUNCTIONdbo.ufn_AuditReport (@filepathvarchar(1000)) ...