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)

Drop Column

By Srinivas Annaswamy,

-- use database
go

-- SQL 2005 and above


/*

exec sp_lib_drop_column 'constratintcheckhead','accountid','l'
exec sp_lib_drop_column 'constratintcheckhead','accountid','d'

 

-- testing

create table constratintcheckhead ( accountid int not nullprimary key ,clientid int not null )
create table constraintcheckdetails ( accountid intnot null ,notesid intnot null primarykey (accountid,notesid) )

 

alter table constratintcheckhead
add constraint DF_accountid default 0 for accountid

alter table constratintcheckhead
add constraint CK_accountid check (accountid >= 0 )

alter table constratintcheckhead
add constraint UQ_account Unique (accountid,clientid )

alter table constraintcheckdetails
add constraint FK_constraintcheckdetails_constratintcheckhead foreign key (accountid)
references constratintcheckhead (accountid)

create index IX_constratintcheckhead_clientid on constratintcheckhead(clientid) withfillfactor = 90
create index IX_constratintcheckhead_clientid_accountid on constratintcheckhead(clientid,accountid) withfillfactor = 90

drop table constratintcheckhead
drop table constraintcheckdetails
Description : Lists/Drops Constartints and indexes for a column and drops the column

Following constraints are checked only

Default,Check, Foreign Key, Primary Key,Unique Key
Indexes : Clustered or Non Clustered

This will not check column is replicated or part of full text etc

Only SQL 2005 and above

WARNING: Once constaints are dropped , column will be dropped
Assumes there are not more than 10 columns in an index

Usage : exec sp_lib_drop_column 'constratintcheckhead','accountid','l'
exec sp_lib_drop_column 'constratintcheckhead','accountid','d'

Input Parameters : @tablename , @columnname ,@flag char(1)
@flag -- 'l' -- list constraints only , 'd' -- drop column , 'b' -- list constraints and drop column

Output Parameters : None

Return Value : None

Record Set : None

Created Date : 10 Jan 2009

Created By : M A Srinivas

Created Version : 1.00

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

SSIS import

returning the ClientID

FORUM

Distinct Latest Records

Want only one entry (distinct record) per accountid

FORUM

SQL Profile clientid

How can I find out what is clientprocessid = 44. Thank you I believe it's the windows processid at t...

FORUM

check 2 date columns for same date

I need to compare the Start Date to the End Date looking for the same date for each clientID

FORUM

FOR XML PATH , for NULL column values

FOR XML PATH , for NULL column values

Tags
ddl    
drop column    
t-sql    
 
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