dbo.QBM_FSQPrimaryKeyDef_S

SQL_SCALAR_FUNCTION

Created 2025-06-27T17:57:01.303 · modified 2026-04-14T23:14:10.343 · source: live DB sys.objects/sys.sql_expression_dependencies.

Open formatted source/search result

Parameters

NameTypeOutput
nvarcharyes
@TableOrTypeNamenvarcharno

Referenced objects

SchemaObjectColumn/minorClass
No SQL expression dependencies in snapshot.

Source excerpt

First extracted SQL definition lines from the exported source. Use the full source page for complete context.

Open full formatted source

1   create   function dbo.QBM_FSQPrimaryKeyDef_S (@TableOrTypeName nvarchar(64)) returns nvarchar(1024)  as begin declare @erg nvarchar(1024) = N''
2  declare @Indextype varchar(64) = null declare @columnName1 varchar(30) declare @columnName2 varchar(30) declare @bucketCount int if exists (select top
3 1 1 from sys.tables t with (readpast) where t.name = @TableOrTypeName ) begin select top 1 @Indextype = i.type_desc , @bucketCount = h.bucket_count from
4 sys.key_constraints c with (readpast) join sys.tables t with (readpast) on c.parent_object_id = t.object_id join sys.indexes i with (readpast) on c.name
5 = i.name and i.is_primary_key = 1  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) left outer join sys.hash_indexes h with (readpast) on h.index_id
6 = i.index_id and h.object_id = i.object_id where t.name = @TableOrTypeName  select top 1 @columnName1 = co.name from sys.key_constraints c with (readpast
7) join sys.tables t with (readpast) on c.parent_object_id = t.object_id join sys.indexes i with (readpast) on c.name = i.name  and i.is_primary_key = 1
8  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) join sys.index_columns ic with (readpast) on ic.object_id = t.object_id and ic.index_id = i.index_id
9 join sys.columns co with (readpast) on t.object_id = co.object_id and co.column_id = ic.column_id where t.name = @TableOrTypeName order by ic.index_column_id
10 select top 1 @columnName2 = co.name from sys.key_constraints c with (readpast) join sys.tables t with (readpast) on c.parent_object_id = t.object_id join
11 sys.indexes i with (readpast) on c.name = i.name  and i.is_primary_key = 1  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) join sys.index_columns
12 ic with (readpast) on ic.object_id = t.object_id and ic.index_id = i.index_id join sys.columns co with (readpast) on t.object_id = co.object_id and co.column_id
13 = ic.column_id where t.name = @TableOrTypeName and co.name <> @columnName1  order by ic.index_column_id desc end else begin  select top 1 @Indextype =
14 i.type_desc , @bucketCount = h.bucket_count from sys.key_constraints c with (readpast) join sys.table_types t with (readpast) on c.parent_object_id = 
15t.type_table_object_id join sys.indexes i with (readpast) on c.name = i.name and i.is_primary_key = 1  and i.is_hypothetical = 0  and i.type not in (3,4
16,5,6) left outer join sys.hash_indexes h with (readpast) on h.index_id = i.index_id and h.object_id = i.object_id where t.name = @TableOrTypeName  select
17 top 1 @columnName1 = co.name from sys.key_constraints c with (readpast) join sys.table_types t with (readpast) on c.parent_object_id = t.type_table_object_id
18 join sys.indexes i with (readpast) on c.name = i.name  and i.is_primary_key = 1  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) join sys.index_columns
19 ic with (readpast) on ic.object_id = t.type_table_object_id and ic.index_id = i.index_id join sys.columns co with (readpast) on co.object_id = t.type_table_object_id
20 and co.column_id = ic.column_id where t.name = @TableOrTypeName order by ic.index_column_id select top 1 @columnName2 = co.name from sys.key_constraints
21 c with (readpast) join sys.table_types t with (readpast) on c.parent_object_id = t.type_table_object_id join sys.indexes i with (readpast) on c.name =
22 i.name  and i.is_primary_key = 1  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) join sys.index_columns ic with (readpast) on ic.object_id = t.type_table_object_id
23 and ic.index_id = i.index_id join sys.columns co with (readpast) on co.object_id = t.type_table_object_id and co.column_id = ic.column_id where t.name
24 = @TableOrTypeName and co.name <> @columnName1  order by ic.index_column_id desc end if @columnName1 > ' ' begin select @erg = N', primary key ' + @Indextype
25 + ' (' + @columnName1 end if @Indextype is null or @Indextype = 'CLUSTERED' begin select @Indextype = '' end if @columnName2 > ' ' begin select @erg =
26 @erg + N', ' + @columnName2 end if @erg > '' begin select @erg = @erg + N')' end if @bucketCount > 0 begin select @erg = @erg + ' with (BUCKET_COUNT = '
27+ ltrim(STR(@bucketCount)) +')' end return(@erg) end 
28

Module relation graph

Loading module relation graph…

Source-derived context

Generated from exported SQL module definitions plus read-only sandbox sys.objects/sys.parameters/sys.sql_expression_dependencies metadata. This is factual source evidence, not a semantic guess.

provenance: SQL definition export provenance: sandbox DB metadata modified: 2026-04-14T23:14:10.343

None extracted.

Summary: reads/joins sys

Declared parameters

ParameterTypeDirection
nvarchar(1024)OUTPUT
@TableOrTypeNamenvarchar(64)input

DML targets

None extracted.

Called routines

None extracted.

Read/join references

SQL dependency metadata

None extracted.

Config/session

Config: None extracted.

Session: None extracted.

DBQueue/tasks

None extracted.

Temp tables / referenced variables

Temp: None extracted.

Variables: @TableOrTypeName @erg @Indextype @columnName1 @columnName2 @bucketCount

Referenced by / reverse dependencies

Generated from live DB metadata, FK rows, and exported SQL dependency/source extraction. This is factual linkage evidence, not inferred behavior.

Referencing objectRelationEvidence
dbo.QBM_FSQTableDefSQL expression dependencydbo · OBJECT_OR_COLUMN
dbo.QBM_FSQTypeDefSQL expression dependencydbo · OBJECT_OR_COLUMN
dbo.QBM_PDatabaseCollationCheckSQL expression dependencydbo · OBJECT_OR_COLUMN