提交 8674b600 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add POSITION_IN_UNIQUE_CONSTRAINT from SQL:2003

上级 1aef492a
...@@ -568,7 +568,8 @@ public class MetaTable extends Table { ...@@ -568,7 +568,8 @@ public class MetaTable extends Table {
"TABLE_SCHEMA", "TABLE_SCHEMA",
"TABLE_NAME", "TABLE_NAME",
"COLUMN_NAME", "COLUMN_NAME",
"ORDINAL_POSITION" "ORDINAL_POSITION",
"POSITION_IN_UNIQUE_CONSTRAINT"
); );
indexColumnName = "TABLE_NAME"; indexColumnName = "TABLE_NAME";
break; break;
...@@ -1948,6 +1949,7 @@ public class MetaTable extends Table { ...@@ -1948,6 +1949,7 @@ public class MetaTable extends Table {
} }
for (int i = 0; i < indexColumns.length; i++) { for (int i = 0; i < indexColumns.length; i++) {
IndexColumn indexColumn = indexColumns[i]; IndexColumn indexColumn = indexColumns[i];
String ordinalPosition = Integer.toString(i + 1);
add(rows, add(rows,
// CONSTRAINT_CATALOG // CONSTRAINT_CATALOG
catalog, catalog,
...@@ -1964,7 +1966,9 @@ public class MetaTable extends Table { ...@@ -1964,7 +1966,9 @@ public class MetaTable extends Table {
// COLUMN_NAME // COLUMN_NAME
indexColumn.columnName, indexColumn.columnName,
// ORDINAL_POSITION // ORDINAL_POSITION
Integer.toString(i + 1) ordinalPosition,
// POSITION_IN_UNIQUE_CONSTRAINT
(constraintType == Constraint.Type.REFERENTIAL ? ordinalPosition : null)
); );
} }
} }
......
...@@ -19,21 +19,21 @@ ALTER TABLE T2 ADD CONSTRAINT FK_1 FOREIGN KEY (C3, C4) REFERENCES T1(C1, C3); ...@@ -19,21 +19,21 @@ ALTER TABLE T2 ADD CONSTRAINT FK_1 FOREIGN KEY (C3, C4) REFERENCES T1(C1, C3);
> ok > ok
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE LIMIT 0; SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE LIMIT 0;
> CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION > CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT
> ------------------ ----------------- --------------- ------------- ------------ ---------- ----------- ---------------- > ------------------ ----------------- --------------- ------------- ------------ ---------- ----------- ---------------- -----------------------------
> rows: 0 > rows: 0
SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE SELECT CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, POSITION_IN_UNIQUE_CONSTRAINT FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE CONSTRAINT_CATALOG = DATABASE() AND CONSTRAINT_SCHEMA = SCHEMA() AND TABLE_CATALOG = DATABASE() AND TABLE_SCHEMA = SCHEMA() WHERE CONSTRAINT_CATALOG = DATABASE() AND CONSTRAINT_SCHEMA = SCHEMA() AND TABLE_CATALOG = DATABASE() AND TABLE_SCHEMA = SCHEMA()
ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION; ORDER BY TABLE_NAME, CONSTRAINT_NAME, ORDINAL_POSITION;
> CONSTRAINT_NAME TABLE_NAME COLUMN_NAME ORDINAL_POSITION > CONSTRAINT_NAME TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT
> --------------- ---------- ----------- ---------------- > --------------- ---------- ----------- ---------------- -----------------------------
> PK_1 T1 C1 1 > PK_1 T1 C1 1 null
> PK_1 T1 C2 2 > PK_1 T1 C2 2 null
> U_1 T1 C3 1 > U_1 T1 C3 1 null
> U_1 T1 C4 2 > U_1 T1 C4 2 null
> FK_1 T2 C3 1 > FK_1 T2 C3 1 1
> FK_1 T2 C4 2 > FK_1 T2 C4 2 2
> rows (ordered): 6 > rows (ordered): 6
DROP TABLE T2; DROP TABLE T2;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论