Home Microsoft SQL Server DigiMailing iRN Contact


  No additional text.


create procedure sys.sp_constr_col_usage_rowset2
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @constr_catalog     sysname = null,
    @constr_schema      sysname = null,
    @constr_name        sysname = null

-- copy & pasted from version 1 of the SProc and removed checks for 1st parameter !

    select  *
            TABLE_CATALOG       = db_name(),
            TABLE_SCHEMA        = schema_name(obj.schema_id),
            TABLE_NAME          = obj.name,
            COLUMN_NAME         = col.name,
            COLUMN_GUID         = convert(uniqueidentifier, NULL),
            COLUMN_PROPID       = convert(int, NULL),
            CONSTRAINT_CATALOG  = db_name(),
            CONSTRAINT_SCHEMA   = schema_name(obj.schema_id),
            CONSTRAINT_NAME     = obj2.name

            sys.all_objects obj inner join
            sys.sysconstraints s_sc on (obj.type in ('S ', 'U ') and s_sc.id = obj.object_id and s_sc.colid <> 0) inner join
            sys.all_objects obj2 on (s_sc.constid = obj2.object_id),
            sys.all_columns col

            (@table_schema is null or schema_id(@table_schema) = obj.schema_id) and
            col.object_id = obj.object_id and
            col.column_id = s_sc.colid
    ) as my_result

    where -- ISSUE - PERF - There is no need of 2 nested selects. Incorporate it in the above select.
        (@column_name  is null or @column_name  = my_result.COLUMN_NAME) and
        (@constr_catalog is null or @constr_catalog  = my_result.CONSTRAINT_CATALOG) and
        (@constr_schema  is null or @constr_schema  = my_result.CONSTRAINT_SCHEMA) and
        (@constr_name  is null or @constr_name  = my_result.CONSTRAINT_NAME)

    order by 1, 2, 3, 4, 5, 6, 7, 8, 9

Last revision 2008RTM

  Query a named instance
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
Zoekmachine optimalisatie
SQL Servers hidden objects
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
sIFR; de combinatie tussen HTML en Flash