SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Find botched constraints, idxs, fks


Find botched constraints, idxs, fks

Author
Message
Bill Talada
Bill Talada
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1242 Visits: 2001
Comments posted to this topic are about the item Find botched constraints, idxs, fks
Nadrek
Nadrek
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1989 Visits: 2729
An interesting query.

I would note that if one is looking for botched foreign keys, one must look for both disabled and enabled but untrusted foreign keys and note them.

I'd also have to modify it to run from a single database against columns on another database (with EXEC 'USE <db>; <statement>' if need be).
henrik staun poulsen
henrik staun poulsen
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2070 Visits: 1222
I'm looking for an explanation for some of the abreviations.

pk is Primary Key
ak is Unique Constraints ??
udx is Unique Index
idx is non unique index

"+" means that the field is an included field in the index

The numbers:
x.y
where x means the "index number" (what is this?)
and y means the Index Column ID

The sproc does a good job in showing the relationship between indexing and FK.
Thank you.

Best regards,
Henrik Staun Poulsen
www.stovi.com



Douglas Osborne-456728
Douglas Osborne-456728
SSC Veteran
SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)SSC Veteran (212 reputation)

Group: General Forum Members
Points: 212 Visits: 327
Here's a quick script to run it against all of your tables. I've still got to figure out your syntax a bit better ;-)

Doug

CREATE PROCEDURE [dbo].[ExamineAllTables]
AS
BEGIN
SET NOCOUNT ON

DECLARE
@TableCnt INT,
@CurrentTable INT,
@Table SYSNAME

CREATE TABLE #TableListing
(
[IndexListingID] INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
[TableName] SYSNAME COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)

INSERT INTO #TableListing( [TableName] )
SELECT [Name]
FROM sys.tables
ORDER BY [Name]

SELECT @TableCnt = @@ROWCOUNT, @CurrentTable = 1

WHILE @CurRentTable <= @TableCnt
BEGIN
SELECT @Table = TableName
FROM #TableListing
WHERE [IndexListingID] = @CurrentTable

EXECUTE dbo.ShowColumnUsage @Table

SET @CurrentTable = @CurrentTable + 1
END
END
Iwas Bornready
Iwas Bornready
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14274 Visits: 885
Thanks for the script.
Bill Talada
Bill Talada
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1242 Visits: 2001
henrik staun poulsen (8/5/2010)
I'm looking for an explanation for some of the abreviations.

pk is Primary Key
ak is Unique Constraints ??
udx is Unique Index
idx is non unique index

"+" means that the field is an included field in the index

The numbers:
x.y
where x means the "index number" (what is this?)
and y means the Index Column ID

The sproc does a good job in showing the relationship between indexing and FK.
Thank you.

Best regards,
Henrik Staun Poulsen
www.stovi.com


PK = Primary Key
AK = Alternate Key
UDX = Unique Index
IDX = Non-Unique Index

+ = Included column

x.y = Index#.Column#

I still use this before each release as a sanity check to spot redundant or missing indexes.
henrik staun poulsen
henrik staun poulsen
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2070 Visits: 1222
thank you very much



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search