Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_constr_col_usage_rowset

  No additional text.


Syntax

create procedure sys.sp_constr_col_usage_rowset
(
    @table_name         sysname,
    @table_schema       sysname = null,
    @column_name        sysname = null,
    @constr_catalog     sysname = null,
    @constr_schema      sysname = null,
    @constr_name        sysname = null
)
as
    select  *
    from
    (
        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

        from
            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

        where
            (
                (@table_schema is null and obj.name = @table_name) or
                object_id(quotename(@table_schema) + '.' + quotename(@table_name)) = obj.object_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
See also

  sp_constr_col_usage_rowset2 (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
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
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash