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 ««12

Ordering Tables To Preserve Referential Integrity Expand / Collapse
Author
Message
Posted Sunday, March 29, 2009 11:00 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 12:57 PM
Points: 1,616, Visits: 1,543
FYI: I referenced this article on my blog: http://www.sqlservercentral.com/blogs/robert_davis/archive/2009/03/29/Do-You-Support-the-Ancient-Ones.aspx



My blog: SQL Soldier
Twitter: @SQLSoldier
My book: Pro SQL Server 2008 Mirroring
Microsoft Certified Master: SQL Server 2008
Principal DBA: Outerwall, Inc.
Also available for consulting: SQL DBA Master
Post #685738
Posted Tuesday, February 9, 2010 1:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 31, 2013 12:31 AM
Points: 2, Visits: 27

Very smart, elegant, beautiful solution/idea.
Thank u for sharing ur brain power with us, thanks a lot.
Post #862686
Posted Tuesday, February 9, 2010 1:47 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 3:10 PM
Points: 52, Visits: 263
Thank you for that.

Those tables not involved in any relationships are not displayed (by design), but to display them simply add this snippet just before the script displays the final answer:

-- Add to answer table those tables involved in no relationships (ie. what's left)
-- Use -1 as Level
INSERT INTO tblAnswer([Level], A)
SELECT -1, name FROM dbo.sysobjects
WHERE OBJECTPROPERTY(id, N'IsUserTable') = 1
AND name NOT IN ('sysdiagrams','tblPreorder','tblAnswer')
AND name NOT IN
(
SELECT DISTINCT A FROM tblAnswer
)


R Glen Cooper
Post #862722
Posted Tuesday, November 16, 2010 7:10 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 12:25 PM
Points: 139, Visits: 384
Excellent script. I needed to drop most of the tables in database, in RI order. This is exactly what I need.

Thanks!
Post #1021490
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse