[#2025] Correctly handle multiple foreign keys defined on the same
column
This commit is contained in:
parent
1ec5cd4ced
commit
a0cd2916e2
@ -523,9 +523,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.tab(1).println("}");
|
||||
|
||||
if (generateRelations() && generateNavigationMethods()) {
|
||||
ForeignKeyDefinition foreignKey = column.getForeignKey();
|
||||
|
||||
if (foreignKey != null) {
|
||||
for (ForeignKeyDefinition foreignKey : column.getForeignKeys()) {
|
||||
printFKSetter(out, column, foreignKey);
|
||||
}
|
||||
}
|
||||
@ -2107,9 +2105,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
// Print references from this foreign key to its related primary key
|
||||
// E.g. in TBookRecord print getTAuthor()
|
||||
// -----------------------------------------------------------------
|
||||
ForeignKeyDefinition foreignKey = column.getForeignKey();
|
||||
if (foreignKey != null && out.printOnlyOnce(foreignKey)) {
|
||||
printFetchFK(out, column, foreignKey);
|
||||
for (ForeignKeyDefinition foreignKey : column.getForeignKeys()) {
|
||||
if (out.printOnlyOnce(foreignKey)) {
|
||||
printFetchFK(out, column, foreignKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -62,10 +62,9 @@ public interface ColumnDefinition extends TypedElementDefinition<TableDefinition
|
||||
List<UniqueKeyDefinition> getUniqueKeys();
|
||||
|
||||
/**
|
||||
* A definition for the foreign key that this column is part of, or
|
||||
* <code>null</code> if this column is not part of a foreign key.
|
||||
* All definitions of foreign keys that this column is part of.
|
||||
*/
|
||||
ForeignKeyDefinition getForeignKey();
|
||||
List<ForeignKeyDefinition> getForeignKeys();
|
||||
|
||||
/**
|
||||
* Whether this column is the table's <code>IDENTITY</code> column.
|
||||
|
||||
@ -47,15 +47,15 @@ public class DefaultColumnDefinition
|
||||
extends AbstractTypedElementDefinition<TableDefinition>
|
||||
implements ColumnDefinition {
|
||||
|
||||
private final int position;
|
||||
private final boolean isIdentity;
|
||||
private final boolean nullable;
|
||||
private final int position;
|
||||
private final boolean isIdentity;
|
||||
private final boolean nullable;
|
||||
|
||||
private boolean primaryKeyLoaded;
|
||||
private UniqueKeyDefinition primaryKey;
|
||||
private List<UniqueKeyDefinition> uniqueKeys;
|
||||
private boolean foreignKeyLoaded;
|
||||
private ForeignKeyDefinition foreignKey;
|
||||
private boolean primaryKeyLoaded;
|
||||
private UniqueKeyDefinition primaryKey;
|
||||
private List<UniqueKeyDefinition> uniqueKeys;
|
||||
private boolean foreignKeyLoaded;
|
||||
private List<ForeignKeyDefinition> foreignKey;
|
||||
|
||||
public DefaultColumnDefinition(TableDefinition table, String name, int position, DataTypeDefinition type,
|
||||
boolean nullable, boolean isIdentity, String comment) {
|
||||
@ -92,10 +92,10 @@ public class DefaultColumnDefinition
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ForeignKeyDefinition getForeignKey() {
|
||||
public final List<ForeignKeyDefinition> getForeignKeys() {
|
||||
if (!foreignKeyLoaded) {
|
||||
foreignKeyLoaded = true;
|
||||
foreignKey = getDatabase().getRelations().getForeignKey(this);
|
||||
foreignKey = getDatabase().getRelations().getForeignKeys(this);
|
||||
}
|
||||
|
||||
return foreignKey;
|
||||
|
||||
@ -91,13 +91,9 @@ public class DefaultForeignKeyDefinition extends AbstractDefinition implements F
|
||||
public int countSimilarReferences() {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
|
||||
for (ColumnDefinition column : table.getColumns()) {
|
||||
ForeignKeyDefinition key = getDatabase().getRelations().getForeignKey(column);
|
||||
|
||||
if (key != null) {
|
||||
if (key.getReferencedTable().equals(getReferencedTable())) {
|
||||
keys.add(key.getName());
|
||||
}
|
||||
for (ForeignKeyDefinition key : getDatabase().getRelations().getForeignKeys(table)) {
|
||||
if (key.getReferencedTable().equals(getReferencedTable())) {
|
||||
keys.add(key.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -46,17 +46,17 @@ import org.jooq.tools.JooqLogger;
|
||||
|
||||
public class DefaultRelations implements Relations {
|
||||
|
||||
private static final JooqLogger log = JooqLogger.getLogger(DefaultRelations.class);
|
||||
private static final JooqLogger log = JooqLogger.getLogger(DefaultRelations.class);
|
||||
|
||||
private Map<Key, ForeignKeyDefinition> foreignKeys = new LinkedHashMap<Key, ForeignKeyDefinition>();
|
||||
private Map<Key, UniqueKeyDefinition> primaryKeys = new LinkedHashMap<Key, UniqueKeyDefinition>();
|
||||
private Map<Key, UniqueKeyDefinition> uniqueKeys = new LinkedHashMap<Key, UniqueKeyDefinition>();
|
||||
private Map<Key, UniqueKeyDefinition> primaryKeys = new LinkedHashMap<Key, UniqueKeyDefinition>();
|
||||
private Map<Key, UniqueKeyDefinition> uniqueKeys = new LinkedHashMap<Key, UniqueKeyDefinition>();
|
||||
private Map<Key, ForeignKeyDefinition> foreignKeys = new LinkedHashMap<Key, ForeignKeyDefinition>();
|
||||
|
||||
private Map<ColumnDefinition, ForeignKeyDefinition> foreignKeysByColumn = new LinkedHashMap<ColumnDefinition, ForeignKeyDefinition>();
|
||||
private Map<ColumnDefinition, UniqueKeyDefinition> primaryKeysByColumn = new LinkedHashMap<ColumnDefinition, UniqueKeyDefinition>();
|
||||
private Map<ColumnDefinition, List<UniqueKeyDefinition>> uniqueKeysByColumn = new LinkedHashMap<ColumnDefinition, List<UniqueKeyDefinition>>();
|
||||
private Map<ColumnDefinition, UniqueKeyDefinition> primaryKeysByColumn = new LinkedHashMap<ColumnDefinition, UniqueKeyDefinition>();
|
||||
private Map<ColumnDefinition, List<UniqueKeyDefinition>> uniqueKeysByColumn = new LinkedHashMap<ColumnDefinition, List<UniqueKeyDefinition>>();
|
||||
private Map<ColumnDefinition, List<ForeignKeyDefinition>> foreignKeysByColumn = new LinkedHashMap<ColumnDefinition, List<ForeignKeyDefinition>>();
|
||||
|
||||
public void addPrimaryKey(String keyName, ColumnDefinition column) {
|
||||
public void addPrimaryKey(String keyName, ColumnDefinition column) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding primary key", keyName + " (" + column + ")");
|
||||
}
|
||||
@ -170,18 +170,17 @@ public class DefaultRelations implements Relations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForeignKeyDefinition getForeignKey(ColumnDefinition column) {
|
||||
public List<ForeignKeyDefinition> getForeignKeys(ColumnDefinition column) {
|
||||
if (!foreignKeysByColumn.containsKey(column)) {
|
||||
ForeignKeyDefinition key = null;
|
||||
List<ForeignKeyDefinition> list = new ArrayList<ForeignKeyDefinition>();
|
||||
|
||||
for (ForeignKeyDefinition foreignKey : foreignKeys.values()) {
|
||||
if (foreignKey.getKeyColumns().contains(column)) {
|
||||
key = foreignKey;
|
||||
break;
|
||||
list.add(foreignKey);
|
||||
}
|
||||
}
|
||||
|
||||
foreignKeysByColumn.put(column, key);
|
||||
foreignKeysByColumn.put(column, list);
|
||||
}
|
||||
|
||||
return foreignKeysByColumn.get(column);
|
||||
@ -192,11 +191,7 @@ public class DefaultRelations implements Relations {
|
||||
Set<ForeignKeyDefinition> result = new LinkedHashSet<ForeignKeyDefinition>();
|
||||
|
||||
for (ColumnDefinition column : table.getColumns()) {
|
||||
ForeignKeyDefinition foreignKey = getForeignKey(column);
|
||||
|
||||
if (foreignKey != null) {
|
||||
result.add(foreignKey);
|
||||
}
|
||||
result.addAll(getForeignKeys(column));
|
||||
}
|
||||
|
||||
return new ArrayList<ForeignKeyDefinition>(result);
|
||||
|
||||
@ -65,10 +65,11 @@ public interface Relations {
|
||||
List<UniqueKeyDefinition> getUniqueKeys(TableDefinition table);
|
||||
|
||||
/**
|
||||
* Get the foreign key for a given column, or <code>null</code> if that
|
||||
* column is not part of a foreign key.
|
||||
* Get a list of foreign keys for a given table, that the column
|
||||
* participates in. Returns an empty list if the given column is not part of
|
||||
* any foreign key.
|
||||
*/
|
||||
ForeignKeyDefinition getForeignKey(ColumnDefinition column);
|
||||
List<ForeignKeyDefinition> getForeignKeys(ColumnDefinition column);
|
||||
|
||||
/**
|
||||
* Get a list of foreign keys for a given table. Returns an empty list if
|
||||
|
||||
@ -22,6 +22,7 @@ DROP TABLE t_book/
|
||||
DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_85/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
@ -267,6 +268,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE VIEW v_library (author, title) AS
|
||||
SELECT a.first_name || ' ' || a.last_name, b.title
|
||||
FROM t_author a JOIN t_book b ON b.author_id = a.id
|
||||
|
||||
@ -13,6 +13,7 @@ DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE t_directory/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_85/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
@ -287,6 +288,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE VIEW v_library (author, title) AS
|
||||
SELECT a.first_name || ' ' || a.last_name, b.title
|
||||
FROM t_author a JOIN t_book b ON b.author_id = a.id
|
||||
|
||||
@ -24,6 +24,7 @@ DROP TABLE t_book/
|
||||
DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
DROP TABLE x_test_case_85/
|
||||
@ -289,6 +290,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT T_AUTHOR.FIRST_NAME || ' ' || T_AUTHOR.LAST_NAME, T_BOOK.TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID
|
||||
|
||||
@ -12,6 +12,7 @@ DROP TABLE t_book/
|
||||
DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
DROP TABLE x_test_case_85/
|
||||
@ -255,6 +256,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT T_AUTHOR.FIRST_NAME || ' ' || T_AUTHOR.LAST_NAME, T_BOOK.TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID
|
||||
|
||||
@ -14,6 +14,7 @@ DROP TABLE t_book/
|
||||
DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_85/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
@ -257,6 +258,16 @@ CREATE TABLE x_test_case_85 (
|
||||
);
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
);
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT T_AUTHOR.FIRST_NAME || ' ' || T_AUTHOR.LAST_NAME, T_BOOK.TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID;
|
||||
|
||||
@ -26,6 +26,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
@ -311,6 +312,16 @@ CREATE TABLE x_test_case_85 (
|
||||
);
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
);
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT CONCAT(T_AUTHOR.FIRST_NAME, ' ', T_AUTHOR.LAST_NAME), T_BOOK.TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID;
|
||||
|
||||
@ -33,6 +33,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
@ -313,6 +314,16 @@ CREATE TABLE x_test_case_85 (
|
||||
);
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
);
|
||||
/
|
||||
|
||||
CREATE TABLE system (id int);/
|
||||
CREATE TABLE class (class int);/
|
||||
CREATE TABLE integer (id int);/
|
||||
|
||||
@ -13,6 +13,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
@ -287,6 +288,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
);
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT T_AUTHOR.FIRST_NAME || ' ' || T_AUTHOR.LAST_NAME, T_BOOK.TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID
|
||||
|
||||
@ -22,6 +22,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
@ -292,6 +293,17 @@ CREATE TABLE x_test_case_85 (
|
||||
COMMENT = 'An unused table in the same schema.';
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
) ENGINE = InnoDB
|
||||
COMMENT = 'An unused table in the same schema.';
|
||||
/
|
||||
|
||||
CREATE OR REPLACE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT CONCAT(A.FIRST_NAME, ' ', A.LAST_NAME), B.TITLE
|
||||
FROM T_AUTHOR A JOIN T_BOOK B ON B.AUTHOR_ID = A.ID;
|
||||
|
||||
@ -26,6 +26,7 @@ DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE t_directory/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
DROP TABLE x_test_case_85/
|
||||
@ -669,6 +670,15 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id NUMBER(7) NOT NULL,
|
||||
ref_name VARCHAR2(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE OR REPLACE VIEW v_library (author, title) AS
|
||||
SELECT a.first_name || ' ' || a.last_name, b.title
|
||||
|
||||
@ -39,6 +39,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
@ -416,6 +417,15 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id INTEGER NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE OR REPLACE VIEW v_library (author, title) AS
|
||||
SELECT a.first_name || ' ' || a.last_name, b.title
|
||||
|
||||
@ -10,6 +10,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
@ -251,6 +252,16 @@ CREATE TABLE x_test_case_85 (
|
||||
);
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
);
|
||||
/
|
||||
|
||||
CREATE VIEW V_LIBRARY AS
|
||||
SELECT T_AUTHOR.FIRST_NAME AUTHOR, T_BOOK.TITLE TITLE
|
||||
FROM T_AUTHOR JOIN T_BOOK ON T_BOOK.AUTHOR_ID = T_AUTHOR.ID;
|
||||
|
||||
@ -41,6 +41,7 @@ DROP TABLE t_book/
|
||||
DROP TABLE t_book_details/
|
||||
DROP TABLE t_author/
|
||||
DROP TABLE t_language/
|
||||
DROP TABLE x_test_case_2025/
|
||||
DROP TABLE x_test_case_71/
|
||||
DROP TABLE x_test_case_64_69/
|
||||
DROP TABLE x_test_case_85/
|
||||
@ -293,6 +294,15 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE VIEW v_library (author, title) AS
|
||||
SELECT a.first_name + ' ' + a.last_name, b.title
|
||||
|
||||
@ -22,6 +22,7 @@ DROP TABLE IF EXISTS t_book/
|
||||
DROP TABLE IF EXISTS t_book_details/
|
||||
DROP TABLE IF EXISTS t_author/
|
||||
DROP TABLE IF EXISTS t_language/
|
||||
DROP TABLE IF EXISTS x_test_case_2025/
|
||||
DROP TABLE IF EXISTS x_test_case_85/
|
||||
DROP TABLE IF EXISTS x_test_case_71/
|
||||
DROP TABLE IF EXISTS x_test_case_64_69/
|
||||
@ -325,6 +326,16 @@ CREATE TABLE x_test_case_85 (
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TABLE x_test_case_2025 (
|
||||
ref_id int NOT NULL,
|
||||
ref_name VARCHAR(10) NOT NULL,
|
||||
|
||||
CONSTRAINT fk_x_test_case_2025_1 FOREIGN KEY(ref_id) REFERENCES x_test_case_85(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_2 FOREIGN KEY(ref_id) REFERENCES x_test_case_71(ID),
|
||||
CONSTRAINT fk_x_test_case_2025_3 FOREIGN KEY(ref_id, ref_name) REFERENCES X_UNUSED(id, name)
|
||||
)
|
||||
/
|
||||
|
||||
CREATE OR REPLACE VIEW V_LIBRARY (AUTHOR, TITLE) AS
|
||||
SELECT A.FIRST_NAME || ' ' || A.LAST_NAME, B.TITLE
|
||||
FROM T_AUTHOR A JOIN T_BOOK B ON B.AUTHOR_ID = A.ID;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user