Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to drop a column in table sql 2000

Posted on 2009-05-16
7
Medium Priority
?
936 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 600 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 1400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how the fundamental information of how to create a table.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

963 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