dbo.QBM_FSQPrimaryKeyDef

SQL_SCALAR_FUNCTION

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

Open formatted source/search result

Parameters

NameTypeOutput
nvarcharyes
@TableNamenvarcharno

Referenced objects

SchemaObjectColumn/minorClass
dboQBM_FGIPrimaryKeyName_FOBJECT_OR_COLUMN

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 (@TableName nvarchar(64)) returns nvarchar(1024) as begin declare @erg nvarchar(1024) = N'' declare
2 @val nvarchar(64) declare @Indextype varchar(64) = null declare @isMemoryOptimized bit = 0 declare @columnName1 varchar(30) declare @columnName2 varchar
3(30) select top 1 @Indextype = i.type_desc , @isMemoryOptimized = t.is_memory_optimized from sys.key_constraints c with (readpast) join sys.tables t with
4 (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 where t.name = @TableName
5  and i.is_hypothetical = 0  and i.type not in (3,4,5,6) if @Indextype is null or @Indextype = 'CLUSTERED' begin select @Indextype = '' end if @isMemoryOptimized
6 = 0 begin select @val = dbo.QBM_FGIPrimaryKeyName_F(@TableName , 1) if @val > ' ' begin select @erg = N'primary key ' + @Indextype + ' (' + @val end select
7 @val = dbo.QBM_FGIPrimaryKeyName_F(@TableName , 2) if @val > ' ' begin select @erg = @erg + N', ' + @val end if @erg > '' begin select @erg = @erg + N')'
8 end end else  begin  select top 1 @columnName1 = co.name from sys.key_constraints c with (readpast) join sys.tables t with (readpast) on c.parent_object_id
9 = t.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,5,6) 
10join sys.index_columns 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
11 = co.object_id and co.column_id = ic.column_id where t.name = @TableName order by ic.index_column_id if @columnName1 > ' ' begin select @erg = N'primary key '
12 + @Indextype + ' (' + @columnName1 end select top 1 @columnName2 = co.name from sys.key_constraints c with (readpast) join sys.tables t with (readpast
13) 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  and i.is_hypothetical = 0  and i.type
14 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 join sys.columns co with (readpast
15) on t.object_id = co.object_id and co.column_id = ic.column_id where t.name = @TableName and co.name <> @columnName1  order by ic.index_column_id desc
16 if @columnName2 > ' ' begin select @erg = @erg + N', ' + @columnName2 end if @erg > '' begin select @erg = @erg + N')' end end  return(@erg) end 
17

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.333

None extracted.

Summary: reads/joins sys

Declared parameters

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

DML targets

None extracted.

Called routines

None extracted.

Read/join references

SQL dependency metadata

Config/session

Config: None extracted.

Session: None extracted.

DBQueue/tasks

None extracted.

Temp tables / referenced variables

Temp: None extracted.

Variables: @TableName @erg @val @Indextype @isMemoryOptimized @columnName1 @columnName2

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.

No reverse dependencies extracted.