![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
You can use SSMS to generate a script for this (that is if you make the change via the graphical interface in SSMS). This option is available through Generate Change Script in the Table Designer menu or if you right-click the table editor. |
#4
| |||
| |||
|
|
You can use SSMS to generate a script for this (that is if you make the change via the graphical interface in SSMS). This option is available through Generate Change Script in the Table Designer menu or if you right-click the table editor. Thanks!!! |
#5
| |||
| |||
|
|
But please do check, double-check, and triple-check the script before executing it on a live server. There have historically been some serious flaws in the scripted code used, that might result in losing all your data if you are unlucky. Maybe things have changed since the last time I looked, but I'd never run a script generated by Enterprise Manager or SQL Server Management Studio without prior minute inspection! |
#6
| |||
| |||
|
|
But please do check, double-check, and triple-check the script before executing it on a live server. There have historically been some serious flaws in the scripted code used, that might result in losing all your data if you are unlucky. Maybe things have changed since the last time I looked, but I'd never run a script generated by Enterprise Manager or SQL Server Management Studio without prior minute inspection! Ok, could you please me tell me which part do I have to check? I though it is the same script that Enterprise Manager launch when I save the modification in the data structure... |
#7
| ||||
| ||||
|
|
o Transsaction scope. The script has many small transactions, but there should be one big transaction. That or just restore a backup if there is any error. |
|
o Constraints are restored with NOCHECK, that should be WITH CHECK. That takes longer time, but the flip side is that the optimiser then can trust the constraints. This can matter a lot in some cases. |
|
o Remove all "go" in the script, and wrap most statements in EXEC. The way script lookas as generated, if there is a batch-aborting error, the transaction is rolled back, and the rest of the statements will be committed. An alternative is to wrap all batches in IF @@transcount > 0 BEGIN END. |
|
o Rewiew that the script only includes the changes you intend. There are situations where EM/SSMS may include a change that you have abandoned. |
#8
| |||
| |||
|
|
o Remove all "go" in the script, and wrap most statements in EXEC. The way script lookas as generated, if there is a batch-aborting error, the transaction is rolled back, and the rest of the statements will be committed. An alternative is to wrap all batches in IF @@transcount > 0 BEGIN END. I must remove all "go" statements because I'll execute the code via jdbc driver. I've not understood what do you mean with the phrase "wrap most statements in EXEC" (sorry but I'm fairly new to SQLServer) |
|
I' also noticed that SSMS, before the ALTER TABLE statement put always some instructions (in the automated generated SQL) that I don't unserstand well... BEGIN TRANSACTION SET QUOTED_IDENTIFIER ON SET ARITHABORT ON SET NUMERIC_ROUNDABORT OFF SET CONCAT_NULL_YIELDS_NULL ON SET ANSI_NULLS ON SET ANSI_PADDING ON SET ANSI_WARNINGS ON COMMIT BEGIN TRANSACTION GO ALTER TABLE xxxxxxx Do you think that I have to execute them from my java program or can I start directly with ALTER TABLE instruction? |
![]() |
| Thread Tools | |
| Display Modes | |
| |