The meta data is from an SQL 2012 Server.
I have posted alot more, find the whole list here.
Goto Definition or MetaData
Definition:
sys.sp_constr_col_usage_rowset(nvarchar @table_name, nvarchar @table_schema
, nvarchar @column_name
, nvarchar @constr_catalog
, nvarchar @constr_schema
, nvarchar @constr_name)
MetaData:
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
No comments:
Post a Comment