DEFINITIONS

Definitions More Info.
Definition ID119
TitleSQL
CategorySCRIPT
DefinitionTABLOLARI_SILME_SCHEMA_ILE_CONSTRAINT
Definition Descriptionselect 'DROP TABLE SMS.' + name from sys.tables where type = 'U'AND SCHEMA_ID=7 SELECT * FROM SYS.schemas --schema ID lerine ilgili database ustune gelerek bulabilirsin select 'DROP TABLE dbo.' + name from sys.tables where type = 'U'AND SCHEMA_ID=1 SELECT * FROM SYS.schemas --constraint olduğundan tanlolari silmeyebilir,o zaman aşağıdaki sql calistirmamiz lazim oncelikle --IKI KERE CALISTIR!!!!!!!!!!!!!!!!!!!! -- t-sql scriptlet to drop all constraints on a table DECLARE @database nvarchar(50) DECLARE @table nvarchar(50) set @database = 'DSMART_SAP' set @table = 'select ''dbo.''+name from sys.tables where type = ''U''AND SCHEMA_ID=1' DECLARE @sql nvarchar(255) WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table) BEGIN select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table--once constraint olduğundan tablolari silmeyebilir,o zaman aşağıdaki sql calistirmamiz lazim oncelikle --IKI KERE CALISTIR!!!!!!!!!!!!!!!!!!!! -- t-sql scriptlet to drop all constraints on a table DECLARE @database nvarchar(50) DECLARE @table nvarchar(50) set @database = 'DSMART_SAP' set @table = 'select ''dbo.''+name from sys.tables where type = ''U''AND SCHEMA_ID=1' DECLARE @sql nvarchar(255) WHILE EXISTS(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table) BEGIN select @sql = 'ALTER TABLE ' + @table + ' DROP CONSTRAINT ' + CONSTRAINT_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_catalog = @database and table_name = @table exec sp_executesql @sql END -----simdide tablolari silme scripti olusturalim select 'DROP TABLE SMS.' + name from sys.tables where type = 'U'AND SCHEMA_ID=7 SELECT * FROM SYS.schemas --schema ID lerine ilgili database ustune gelerek bulabilirsin select 'DROP TABLE dbo.' + name from sys.tables where type = 'U'AND SCHEMA_ID=1 SELECT * FROM SYS.schemas
RecordBycunay
Record Date20-02-2012 17:47:23
Düzenle
Kopyala
Sil