--Determine if a stored procedure exists
if exists(Select* fromsysobjectswhereid = object_id (N' [p_createtable] ') and
OBJECTPROPERTY (ID, N' Isprocedure ') = 1)
Drop procedure[P_createtable]
--Create procP_createtable
-- as
--Create TableTUser (CID nvarchar (), name nvarchar (), ageint, dept nvarchar (50))
--EXEC(' p_createtable ')
--Determine if the database DBA exists
--Create DatabaseDba
if exists(Select* fromsys.databaseswhereName =' DbA ')
Drop Database[DbA]
--Determine if the table TableA exists
--CREATE TABLETableA (ID NVARCHAR (), name NVARCHAR (50))
if exists(Select* fromsysobjectswhereid = object_id (N' [TableA] ') andOBJECTPROPERTY (ID, N' isusertable ') = 1)
Drop Table[TableA]
--Determine if stored procedure p_createtable exists
--Create procP_createtable as
--Create Table User(CID nvarchar (), name nvarchar (), ageint, dept nvarchar (50))
--EXEC(' p_createtable ')
if exists(Select* fromsysobjectswhereid = object_id (N' [p_createtable] ')
andOBJECTPROPERTY (ID, N' Isprocedure ') = 1)
Drop procedure[P_createtable]
--Determine whether the view V_tableab exists
--CREATE VIEWV_tableab as
--SELECTA.id,a.name fromTableA A
IF EXISTS(SELECT* fromSys.viewsWHEREName=' V_tableab ')
DROP VIEWV_tableab--PRINT ' existence '
--Determine if the column column1 exists in the table TableA
--CREATE TABLETableA (ID NVARCHAR (), NAME NVARCHAR (50))--Test data
if exists(Select* fromsyscolumnswhereID=OBJECT_ID (' TableA ') andName=' Column1 ')
Alter TableTableADrop columnColumn1
--Determine if the table TableA has an index Index1
Create IndexIndex1 onTableA (Id,name)--(CREATE INDEX) create a nonclustered index on the ID name two fields
if exists(Select* fromsysindexeswhereID=OBJECT_ID (' TableA ') andName=' index1 ')
--if exists(SelectName fromSys.indexeswhereName = N' Index1 ')
DROP INDEXIndex1 onTableA--Delete index
Select* fromSys.indexeswhereName =' Index1 '--View Index
--Create a temporary table (cached only when executing SQL)
DECLARE@tableATABLE(ID NVARCHAR (), NAME NVARCHAR (50))
INSERT into@tableA (Id,name)VALUES(' AAA ',' BBB ')
SELECT* from@tableA
--Build the library:
------------------------------------------------------------------------
Use Master
Go
if exists(Select* fromsys.databaseswhereName=' Caredb ')
Drop DatabaseCaredb
Go
Create DatabaseCaredb
on(
Name=' Caredb_data ',
Filename=' E:\DB\CareDB_Data.mdf '
)
Log on(
Name=' Caredb_data_log ',
Filename=' E:\DB\CareDB_Data.ldf '
)
Go
--Build table:
------------------------------------------------------------------------
UseCaredb
if exists(Select* fromsysobjectswhereName=' Largedatas ')
Drop TableLargedatas
Go
Create TableLargedatas (
Idvarchar(36),
[FileName]varchar(100),
Content image,
Descriptionsvarchar(100)
)
Go
SQL note [SQL judgment exists] [long-term update] (-2015.4)