public class CreateForeignKey extends MySqlPart
Generates an ALTER TABLE...ADD CONSTRAINT
statement to add a foreign key constraint in MySQL.
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
Constructor and Description |
---|
CreateForeignKey() |
CreateForeignKey(String constraintName,
String primaryTableName,
String foreignTableName) |
Modifier and Type | Method and Description |
---|---|
void |
collectSqlFragment(CodeWriter writer) |
String |
getConstraintName() |
List<String> |
getForeignKeyColumnNames() |
String |
getForeignTableName() |
ForeignKeyAction |
getOnDeleteAction() |
ForeignKeyAction |
getOnUpdateAction() |
List<String> |
getPrimaryKeyColumnNames() |
String |
getPrimaryTableName() |
CreateForeignKey |
setConstraintName(String constraintName) |
CreateForeignKey |
setForeignKeyColumnNames(List<String> foreignKeyColumnNames) |
CreateForeignKey |
setForeignKeyColumnNames(String... foreignKeyColumnNames) |
CreateForeignKey |
setForeignTableName(String foreignTableName) |
CreateForeignKey |
setOnDeleteAction(ForeignKeyAction onDeleteAction) |
CreateForeignKey |
setOnUpdateAction(ForeignKeyAction onUpdateAction) |
CreateForeignKey |
setPretty(boolean pretty)
Indicates if line breaks and indentations should be added to output DDL (default false).
Example output (pretty = true):
ALTER TABLE products
Example output (pretty = false): ALTER TABLE products ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id) REFERENCES product_groups ON DELETE CASCADE ON UPDATE CASCADE |
CreateForeignKey |
setPrimaryKeyColumnNames(List<String> primaryKeyColumnNames) |
CreateForeignKey |
setPrimaryKeyColumnNames(String... primaryKeyColumnNames) |
CreateForeignKey |
setPrimaryTableName(String primaryTableName) |
escapeKeyword, placeBackTicks
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
public CreateForeignKey setPretty(boolean pretty)
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
ALTER TABLE products ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id) REFERENCES product_groups ON DELETE CASCADE ON UPDATE CASCADE
public void collectSqlFragment(CodeWriter writer)
collectSqlFragment
in class SqlPart
public String getForeignTableName()
public CreateForeignKey setForeignTableName(String foreignTableName)
public String getPrimaryTableName()
public CreateForeignKey setPrimaryTableName(String primaryTableName)
public String getConstraintName()
public CreateForeignKey setConstraintName(String constraintName)
public CreateForeignKey setForeignKeyColumnNames(List<String> foreignKeyColumnNames)
public CreateForeignKey setForeignKeyColumnNames(String... foreignKeyColumnNames)
public CreateForeignKey setPrimaryKeyColumnNames(List<String> primaryKeyColumnNames)
public CreateForeignKey setPrimaryKeyColumnNames(String... primaryKeyColumnNames)
public ForeignKeyAction getOnUpdateAction()
public CreateForeignKey setOnUpdateAction(ForeignKeyAction onUpdateAction)
public ForeignKeyAction getOnDeleteAction()
public CreateForeignKey setOnDeleteAction(ForeignKeyAction onDeleteAction)
Copyright (c) 2006-2024 North Concepts Inc. All Rights Reserved.