Below are some script templates we use in our database build scripts:
Template script to add a new column to an existing table: in this example, we are adding a Type field with data type Varchar(50) to the HR_Vacancy Table
If Exists(Select * From Sys.Objects Where Object_Id = Object_Id(N'[dbo].[HR_VACANCY]') And Type = 'U')
And NOT Exists(Select * From Sys.Columns Where Name = 'Type' And Object_Id = Object_Id(N'[dbo].[HR_VACANCY]'))
Begin
Alter Table dbo.HR_VACANCY ADD Type VARCHAR(50) NULL
Print 'Added column Type varchar(50) on table HR_VACANCY'
End
GO
Procedure Comment Template
/*--- Summary----------------------------------------------------------------------------
Name: {Procedure Name}
Purpose: {Brief Descrition of the procedure}
Author: {Your name}
Created Date: {Date Created}
--- Dependencies ---List where this procedure is used and any links to other procedures
--- Business Rules --- List any business rules that may apply
--- Modification History---------------------------------------------------------------
Date: Author: Reference: Purpose:
----------------------------------------------------------------------------------------------*/
SCR Release Header
DECLARE @suser_sname VARCHAR(50)
, @machine VARCHAR(200)
, @sMsg VARCHAR(MAX)
, @sModule VARCHAR(100)
SELECT
@suser_sname = SUSER_SNAME()
, @machine = HOST_NAME()
SET @sMsg = '266 - POS7.2.0.9 - SCR5986'
SET @sModule = 'Link POS'
EXEC Dbo.Lbs_Logmessage @sUser = @suser_sname , @sModule = @sModule , @sMsg = @sMsg , @sStatus = 'Upgrade' , @sMachine = @machine
PRINT @sMsg
|