Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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)

spAddField

By TJay Belt,

spAddField is the proc I use to add all fields to the db in our upgrade scripts.  With this proc, you pass it the tablename, fieldname, datatype, and null or not null.  This will call spGetFieldsExists and see if the fields exists or not.  If it does, spAddField will drop that column.  Then it readds it.  This allows me to execute a field add script over and over and not ever error because the field exists.  It drops the field, assuming that the new version is different. 
  Side effects of this is that the position of the field will change, if it exists already.  But usually its a new field, and its ok to run it over an over, since its adding it at the end anyway.

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

Concatenate existing fields SQL server

concatenate existing fields SQL server

FORUM

Adding a new NOT NULL field to an existing table

Adding a new NOT NULL field to an existing table

FORUM

add a new field on the existing non-cluster index on the existing table

add a new field on the existing non-cluster index on the existing table

FORUM

Exists and IF Exists

Exists and IF Exists

FORUM

Add identity field to an existing table, change clustered primary key to non-clustered ,and created a clustered index on the new identity field

Add identity field to an existing table, change clustered primary key to non-clustered ,and created ...

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones