Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Ultimate Alter Script generator

By abmore,

@vTableName = Table to be updated.
@vColumnName = Column to be added/updated.
@vColumnDT = Column Data Type.
@vColumnDF = Column Default value.
@bIsNULL = Is nullable column boolean value
@bNewColFlag = 0:Existing Col, 1:New Column boolean value
@FKtableName = If New col is Foreign Key pass the FK Table otherwise pass empty string ''
@FKColName = If New col is Foreign Key pass the FK Table Column Name otherwise pass empty string ''

 

Expected Result:

IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'Employee' AND column_name = 'SSNNumber') 
ALTER TABLE dbo.Employee ALTER COLUMN SSNNumber NVARCHAR(10) NULL DEFAULT ('N')
GO

 

 

 

Total article views: 1182 | Views in the last 30 days: 2
 
Related Articles
FORUM

column size

column size

FORUM

Computed Column

Computed Column

FORUM

split columns

Split columns

FORUM

alter column

alter column

FORUM

add column between two column

add column between two column

Tags
t-sql    
 
Contribute