Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Administering
»
Filegroups
Filegroups
Rate Topic
Display Mode
Topic Options
Author
Message
darwin.maramot
darwin.maramot
Posted Sunday, December 06, 2009 6:09 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, September 14, 2010 1:10 AM
Points: 7,
Visits: 39
Hi guys
I have a problem, i'd created a new file group and i wanted to transfer some tables to the new one. all you need to do is transfer the clustered index right? so i did it. seems that i cannot transfer a table to my newly created file group. error shows that i cannot drop my primary key because it is being referenced by a foreign key constraint. am really clueless right now...
could you help me out... thanks!!!
this is my script.
USE [Virtuabanker]
GO
/****** Object: Index [PK_tbl_audit_master_1__13] Script Date: 12/07/2009 09:01:38 ******/
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tbl_audit_master]') AND name = N'PK_tbl_audit_master_1__13')
ALTER TABLE [dbo].[tbl_audit_master] DROP CONSTRAINT [PK_tbl_audit_master_1__13]
GO
USE [Virtuabanker]
GO
/****** Object: Index [PK_tbl_audit_master_1__13] Script Date: 12/07/2009 09:01:38 ******/
ALTER TABLE [dbo].[tbl_audit_master] ADD CONSTRAINT [PK_tbl_audit_master_1__13] PRIMARY KEY CLUSTERED
(
[log_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [SECONDARY]
GO
this is the error result
Msg 3725, Level 16, State 0, Line 4
The constraint 'PK_tbl_audit_master_1__13' is being referenced by table 'tblc_audit_acct_grp', foreign key constraint 'FK_tblc_audit_acct_grp_tbl_audit_master'.
Msg 3727, Level 16, State 0, Line 4
Could not drop constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 3
Table 'tbl_audit_master' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 3
Could not create constraint. See previous errors.
Post #829585
Tristan Chiappisi
Tristan Chiappisi
Posted Sunday, December 06, 2009 7:36 PM
SSC Rookie
Group: General Forum Members
Last Login: Yesterday @ 11:23 AM
Points: 44,
Visits: 290
It appears that the 'tblc_audit_acct_grp' table has a foreign key reference to the tbl_audit_master table. You'll need to drop the foreign key reference from the tblc_audit_acct_grp (FK_tblc_audit_acct_grp_tbl_audit_master) and then rerun the statement.
Post #829593
darwin.maramot
darwin.maramot
Posted Sunday, December 06, 2009 9:18 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, September 14, 2010 1:10 AM
Points: 7,
Visits: 39
Tristan Chiappisi (12/6/2009)
It appears that the 'tblc_audit_acct_grp' table has a foreign key reference to the tbl_audit_master table. You'll need to drop the foreign key reference from the tblc_audit_acct_grp (FK_tblc_audit_acct_grp_tbl_audit_master) and then rerun the statement.
thanks tristan, what would happen to the table that has the foreign key (tblc_audit_acct_grp), will the foreign key constrain rebuild itself after i transfer the table to the new filegroup?
Post #829623
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Sunday, December 06, 2009 9:35 PM
SSC-Dedicated
Group: Administrators
Last Login: Today @ 3:26 PM
Points: 31,425,
Visits: 13,738
No, you will need to manually rebuild the FK constraint
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #829629
darwin.maramot
darwin.maramot
Posted Sunday, December 06, 2009 10:52 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, September 14, 2010 1:10 AM
Points: 7,
Visits: 39
thanks steve!
Post #829650
Pei Zhu-415513
Pei Zhu-415513
Posted Monday, December 07, 2009 7:21 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 1,050,
Visits: 2,767
I think you can try to
create clustered index with DROP_EXISTING clause.
Therefore you can proceed w/o drop FK.
Post #829841
Fernando Franco
Fernando Franco
Posted Sunday, March 17, 2013 5:54 PM
Forum Newbie
Group: General Forum Members
Last Login: Friday, May 10, 2013 7:13 AM
Points: 1,
Visits: 10
hi , have you tried with this command ?
ALTER TABLE [tbl_audit_master]
DROP CONSTRAINT [PK_tbl_audit_master_1__13] WITH (MOVE TO SECONDARY)
then
ALTER TABLE [tbl_audit_master]
ADD CONSTRAINT [PK_tbl_audit_master_1__13] PRIMARY KEY CLUSTERED
( [log_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [SECONDARY]
Best regards ,
Fernando Franco.
Post #1432048
GilaMonster
GilaMonster
Posted Monday, March 18, 2013 2:16 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:49 PM
Points: 37,722,
Visits: 29,977
Please note: 3 year old thread.
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #1432098
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.