March 19, 2023 By Teratrax

There are two scenarios in SQL Server that can leave tables with rows that are not bound by an existing FOREIGN KEY constraint or CHECK constraint:

Το Beekeeper Studio Είναι Ένα Δωρεάν & Ανοιχτού Κώδικα GUI Βάσης Δεδομένων

Το καλύτερο εργαλείο SQL query & editor που έχω χρησιμοποιήσει. Παρέχει όλα όσα χρειάζομαι για να διαχειριστώ τη βάση δεδομένων μου. - ⭐⭐⭐⭐⭐ Mit

Το Beekeeper Studio είναι γρήγορο, διαισθητικό και εύκολο στη χρήση. Το Beekeeper υποστηρίζει πολλές βάσεις δεδομένων και λειτουργεί εξαιρετικά σε Windows, Mac και Linux.

Η έκδοση Linux του Beekeeper είναι 100% πλήρης, χωρίς περικοπές και χωρίς συμβιβασμούς στα χαρακτηριστικά.
  1. Newly added constraints ignore existing table data if created using “WITH NOCHECK”.
  2. Re-enabled constraints ignore all table updates and inserts that took place since the constraint was disabled (disabled constraints appear with a red icon in Teratrax Database Manager. Right-click on constraint name to enable it).

Use DBCC CHECKCONSTRAINS to check the integrity of your FOREIGN KEY constraints and CHECK constraints and make sure there are no constraint violations. The command returns a list of rows containing all violations. DBCC CHECKCONSTRAINTS does not return any rows if there are no constraint violations.

Syntax

To check all constraints in the current database:

DBCC CHECKCONSTRAINTS

To check all constraints on a single table:

DBCC CHECKCONSTRAINTS ('table1')

You can run this SQL command from any SQL query window. By default, DBCC CHECKCONSTRAINTS returns the first 200 rows only.

DBCC CHECKCONSTRAINTS checks against enabled constraints only unless WITH ALL_CONSTRAINTS is specified. The returned result consists of table name, constraint name and a WHERE clause that identifies the violating row in the table.