Are you working with someone else’s schema and they haven’t declared nice names for all their constraints?
Unfortunately, it is all too easy to create a table like this: 529 more words
Fill Factor is an important component to think of when creating an index.
It is pretty well known how to use the with clause to specify Fill Factor, targeted groups when creating an Index. 229 more words
In this blog, we’ll discuss about Integrity constraint in SQL Server.
Integrity constraint are rules implemented in the tables to guarantee the accuracy, completeness, or consistency of data in tables and keep safe the business logic of the schema design.Constraints are part of a database schema definition… 118 more words
Here is a small script to get information about the Primary Key column(s) and Foreign Key column(s) in SQL Server.
;WITH GETINFO AS ( SELECT DBNAME = CONVERT(SYSNAME,DB_NAME()), OWNERNAME = CONVERT(SYSNAME,SCHEMA_NAME(OBJ1.SCHEMA_ID)), = CONVERT(SYSNAME,OBJ1.NAME), PKCOLUMN_NAME = CONVERT(SYSNAME,COL1.NAME), = CONVERT(SYSNAME,OBJ2.NAME), FKCOLUMN_NAME = CONVERT(SYSNAME,COL2.NAME), ORDINALPOSITION = ISNULL(CONVERT(SMALLINT,FKCOL.CONSTRAINT_COLUMN_ID),0), = CONVERT(SYSNAME,OBJECT_NAME(FK.OBJECT_ID)), = CONVERT(SYSNAME,I.NAME) FROM SYS.ALL_OBJECTS OBJ1, SYS.ALL_OBJECTS OBJ2, SYS.ALL_COLUMNS COL1, SYS.ALL_COLUMNS COL2, SYS.FOREIGN_KEYS FK INNER JOIN SYS.FOREIGN_KEY_COLUMNS FKCOL ON (FKCOL.CONSTRAINT_OBJECT_ID = FK.OBJECT_ID) INNER JOIN SYS.INDEXES I ON (FK.REFERENCED_OBJECT_ID = I.OBJECT_ID AND FK.KEY_INDEX_ID = I.INDEX_ID) WHERE OBJ1.OBJECT_ID = FK.REFERENCED_OBJECT_ID AND OBJ2.OBJECT_ID = FK.PARENT_OBJECT_ID AND COL1.OBJECT_ID = FK.REFERENCED_OBJECT_ID AND COL2.OBJECT_ID = FK.PARENT_OBJECT_ID AND COL1.COLUMN_ID = FKCOL.REFERENCED_COLUMN_ID AND COL2.COLUMN_ID = FKCOL.PARENT_COLUMN_ID ),SHOWINFO AS ( SELECT DISTINCT DBNAME,OWNERNAME,,, PRIMARYKEYCOLUMNNAMES= REPLACE( (SELECT A.PKCOLUMN_NAME AS FROM GETINFO A WHERE A.94 more words