Solved

Need to drop a column in table sql 2000

Posted on 2009-05-16
7
850 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now