I am trying to create a large script of the database changes created for each release in SQLServer-2008. For each release, all the scripts are wrapped in a statement of BEGIN and END tags for that release.
Most script scripts are okay manually, but if I want to do something like a new field in the middle of a table, but at the end of that the SQLSERVER auto-generated script is quite large, a Trigger
, temp table
, etc.
I noticed that I had to remove all the geo statements in all the scripts. After removing all of them, I still get the following error:
Message 156, level 15, state1, line 10641 keyword has the wrong syntax 'TRIGGER'
Then I tried to wrap all the triggers in the EXEC ('')
statement and I still get an error:
message 105, level 15, state 1, process T_I_ProoformaWhatIf, character string 'after line 5 unimaginative quotation marks)' masterdbows Below is a example of a script that I set in IF, BEGIN, END:
Can not be set on SET QUOTED_IDENTIFIER SET ARITHABORT ON set NUMERIC_ROUNDABORT SET CONCAT_NULL_YIELDS_NULL on ANSI_NULL set on ANSI_PADDING ANSI_WARNINGS COMMIT sign on Transpactation Go to create table dbo.Tmp_Table1 (id ET not zero identity (1, 1), column 1 NIT void, column 2 int no zero, column 3 nv archar (50) not NULL, NewColumn nvarchar (50) zero, Column4 boat (53) zero, Column5 boat (53) zero) Rathmic] GO ALTER table dbo.Tmp_Table1 set (LOCK_ESCALATION = table) GO set identity_insert dbo.Tmp_Table1 exists (select from * dbo.Table1) EXEC ('dbo.Tmp_Table1 (number, column1, column2, column3, newColumn , Column4, Column5) from the selection number, column1, column2, column3, newColumn, Column4, to Column5 with dbo.Table1 (HOLDLOCK TABLOCKX)) Go Set Identity_insert dbo.Tmp_Table1 Separate from Drop Table dbo. Table1 GO executed sp_rename N'dbo.Tmp_Table1 ', N'Table1', 'Object' Go ALTER table dbo.Table1 Add barrier PK_Table1 with primary key cluster (column 1, column 3, column 3) Create [primary] trigger on STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON [DBO]. [T_I_Table1] DBO.Table 1 ON on Master. INSERT AS DECLARE @ User Name varchar (50) SELECT @UserName = REPLACE (MasterCart (from CAST (con text_info as VARCHAR (50)), CHAR (0), '') dbo .sysprocesses WHERE spid = @@ spid IF (ASCII (user name) & lt;> 0) Startup Table1 set InsertUserId = @username, InsertDate = GetDate (), UpdateUserId = @Username, updated = GetDate () From where the Table1.Id = inserted.Id end another update Table1 set InsertDate = GetDate (), updated start = GetDate () inserted from where Table1.Id = inserted.Id originated GO TRIGGER [dbo] We do. [T_U_Table1] Announcement of the update on dbo.Table1 @ Select username (50) for varchar @ user name = REPLACE (cast (context_info (50)) as of vARCHAR, CHAR (0), '') master. From dbo.sysprocesses, where spin1@@ spid IF (ASCII (user name) of & lt;> 0) start update table1 set UpdateUserId = @ User Name, updated = GetDate () where Table1 was inserted. Id = inserted.Id end restart update Table1 set updated = GetDate () inserted where Table1.Id = inserted.Id is selected to end Has_Perms_By_Name COMMIT (N'dbo.Table1 ',' and As ALT_Per, Has_Perms_By View_def_Per, Has_Perms_By_Name (N'dbo.Table1 ',' Object ',' Control ') as Contr_Per
Any suggestion or advice better to do this whole thing will be great.
This again stops working by wrapping the triggers in the excise ('').
Here are 2 tricks:
- Get all go extract details
-
in EXEC ('') Wrap like trigger statement
make EXEC ('TRIGGER [dbo]. [T_U_Table1] ON dbo.Table1') .. ...
No comments:
Post a Comment