fixed mssql primary key respects column order

This commit is contained in:
SPRINX0\prochazka
2024-11-08 12:13:00 +01:00
parent c750bd04ad
commit 319580554f
7 changed files with 62 additions and 14 deletions

View File

@@ -1,15 +1,24 @@
module.exports = `
select o.object_id, pureName = t.Table_Name, schemaName = t.Table_Schema, columnName = c.Column_Name, constraintName=t.constraint_name from
INFORMATION_SCHEMA.TABLE_CONSTRAINTS t,
sys.objects o,
sys.schemas s,
INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE c
where
c.Constraint_Name = t.Constraint_Name
and t.table_name = o.name
and o.schema_id = s.schema_id and t.Table_Schema = s.name
and c.Table_Name = t.Table_Name
and Constraint_Type = 'PRIMARY KEY'
SELECT
i.object_id AS objectId,
o.name AS pureName,
s.name AS schemaName,
c.name AS columnName,
i.name AS constraintName
FROM
sys.indexes i
INNER JOIN
sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
INNER JOIN
sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id
INNER JOIN
sys.objects o ON i.object_id = o.object_id
INNER JOIN
sys.schemas s ON o.schema_id = s.schema_id
WHERE
i.is_primary_key = 1
and o.object_id =OBJECT_ID_CONDITION
and s.name =SCHEMA_NAME_CONDITION
ORDER BY
ic.key_ordinal
`;