Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Foreign Key issues Expand / Collapse
Author
Message
Posted Monday, January 14, 2008 11:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, March 17, 2008 9:43 AM
Points: 13, Visits: 93
I moved two tables from one server to another... after moving, the foreign key relationship is missing on one of the columns in the table in the destination server..does anybody have any idea as to how to add the FK to that column so that the relationship is maintained properly..


Thanks
Post #442567
Posted Monday, January 14, 2008 7:31 PM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Friday, April 5, 2013 4:43 PM
Points: 1,473, Visits: 1,314
Go to your source database to generate;
Excerpt your desired snippet of script;
Run it on your target database.
Post #442791
Posted Friday, February 15, 2008 10:46 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, October 25, 2010 6:09 AM
Points: 1,621, Visits: 409
Hi,

The best thing is export the source tables with all the grants,Primary key,Foreign Keys and Indexes.

Or
use the below syntax

Ex:
ALTER TABLE ORDERS
ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID);

Thanks -- Vj
http://dotnetvj.blogspot.com


Thanks -- Vijaya Kadiyala
www.dotnetvj.com
SQL Server Articles For Beginers



Post #456420
Posted Sunday, February 17, 2008 2:13 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 1:45 PM
Points: 1,862, Visits: 3,609
Disco (1/14/2008)
I moved two tables from one server to another... after moving, the foreign key relationship is missing on one of the columns in the table in the destination server..does anybody have any idea as to how to add the FK to that column so that the relationship is maintained properly..


Thanks


If, while the FK constraint was absent, there have been modifications to the table(s) involved, addition of the constraint will give you an error if there are any data integrity violations.

In any case, it wouldn't hurt to make sure the added constraint is "trusted":

ALTER TABLE ;

Make sure there are no other non-trusted constraints in your database:

USE ;

SELECT OBJECT_NAME(parent_object_id) AS table_name, name
FROM sys.check_constraints
WHERE is_not_trusted = 1
UNION ALL
SELECT OBJECT_NAME(parent_object_id) AS table_name, name
FROM sys.foreign_keys
WHERE is_not_trusted = 1
ORDER BY table_name;

Basically, a constraint can be in one of the following stages:
- disabled: not enforcing data integrity
- enabled: enforcing data integrity on new data
- trusted: enforcing data integrity on new and existing data

The optimizer makes use of this info to construct efficient query plans.

See, for example,
http://sqlblog.com/blogs/tibor_karaszi/archive/2008/01/12/non-trusted-constraints-and-performance.aspx


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #456699
Posted Sunday, February 17, 2008 2:25 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 1:45 PM
Points: 1,862, Visits: 3,609
Oops, let's try this again:

ALTER TABLE your_table WITH CHECK CHECK CONSTRAINT your_constraint;

USE your_db;

SELECT OBJECT_NAME(parent_object_id) AS table_name, name
FROM sys.check_constraints
WHERE is_not_trusted = 1
UNION ALL
SELECT OBJECT_NAME(parent_object_id) AS table_name, name
FROM sys.foreign_keys
WHERE is_not_trusted = 1
ORDER BY table_name


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #456700
Posted Sunday, February 17, 2008 2:56 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 26, 2014 7:44 AM
Points: 6,731, Visits: 8,476
Maybe this script can help you a bit...
http://www.sqlservercentral.com/scripts/Miscellaneous/31808/



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #456703
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse