Solved

Need to drop a column in table sql 2000

Posted on 2009-05-16
7
898 Views
Last Modified: 2013-11-30
when building a merge replication a column was added to all of my tables. I need to remove this column. I have run the following in querry anaalyzer

alter table tablename
drop column  rowguid

I get the following error

Server: Msg 5074, Level 16, State 1, Line 1
The object 'DF__FAHead__rowgui__2DB1C7EE' is dependent on column 'rowguid'.
Server: Msg 5074, Level 16, State 1, Line 1
The index 'index_165575628' is dependent on column 'rowguid'.
Server: Msg 4922, Level 16, State 1, Line 1
ALTER TABLE DROP COLUMN rowguid failed because one or more objects access this column.

This column must be remover ASAP. I have tried to remove it by right clicking and selecting delete but delete is not available.

How do I delete this column?
0
Comment
Question by:jimmylew52
  • 3
  • 3
7 Comments
 
LVL 15

Assisted Solution

by:MohammedU
MohammedU earned 150 total points
ID: 24404970
Before dropping the column you have to remove the index and default attached to this column...

drop index tablename.indexname
go
DROP DEFAULT <defaultname>
go
alter table tablename drop column....
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24404996
As those columns are added by SQL Server for replication, you have to first delete the replication activity, remove the publishing activity for this database and then try issuing the drop column statement given below

alter table tablename drop column columnname

This should help you out.
0
 
LVL 1

Author Comment

by:jimmylew52
ID: 24405037
MohammedU:

What might the default <defaultname> be or how do I find it

rrjegan17:

replication has already been deleted.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 350 total points
ID: 24405065
Ok.. To make it clear giving the steps below:
1. Drop the existing Merger replication
 
exec sp_dropmergesubscription @publication = 'MyPublicatioName', @subscriber = 'MySubscriberName', @subscriber_db = 'MySubscriptionDatabase'
 
2. Stop all replication triggers
declare test cursor for select sysobjects.name, tablename=object_name(parent_obj) From sysobjects join sysmergearticles
on object_name(sysobjects.parent_obj)=sysmergearticles.name
where sysobjects.type='tr'
open test
declare @tablename sysname
declare @triggername sysname
declare @string varchar(1000)
declare @newstring varchar(1000)
fetch next from test into @triggername, @tablename
while @@fetch_status=0
begin
set @string='drop trigger @triggername'
select @newstring=replace(replace(@string, '@tablename',@tablename),'@triggername',@triggername)
print @newstring
exec (@newstring)
fetch next from test into @triggername, @tablename
end
close test
deallocate test
 
3. Finally run Cleanup subscription
 
sp_mergesubscription_cleanup [ @publisher =] 'publisher'
        , [ @publisher_db =] 'publisher_db'
        , [ @publication =] 'publication'
 
4. Drop the Rowguid columns using the syntax provided earlier now if it exists.

Open in new window

0
 
LVL 1

Author Comment

by:jimmylew52
ID: 24405080
All publications and subscriptios have been deleted. Ran your script

sp_mergesubscription_cleanup [ @publisher =] 'servername'
        , [ @publisher_db =] 'T2Com'
        , [ @publication =] 'T2Com'

received error

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'servername'.

alter table FADetailArchive
drop column  rowguid

Server: Msg 5074, Level 16, State 1, Line 1
The object 'DF__FADetailA__rowgu__336AA144' is dependent on column 'rowguid'.
Server: Msg 4922, Level 16, State 1, Line 1
ALTER TABLE DROP COLUMN rowguid failed because one or more objects access this column.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24405094
Hope servername is the sysname and more details below:

http://msdn.microsoft.com/en-us/library/ms188391(SQL.90).aspx
0
 
LVL 1

Author Comment

by:jimmylew52
ID: 24405250
Wasn't what I needed. Here is what is working.

sp_HelpConstraint tablename

alter table Tablename drop constraint (enter constraint for rowguid Here - from previous command)

alter table Conversation drop column rowguid

Get an error stating an Index is dependant

drop index Conversation.(enter index from error message above)

alter table Conversation drop column rowguid

This works but hopefully it can be scripted as I have to run this several hundred times;

I am not good at sql scripting. any ideas on how to do this?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question