gpt4 book ai didi

java - Liquibase:如何在列标签中设置外键约束?

转载 作者:IT老高 更新时间:2023-10-28 20:48:10 24 4
gpt4 key购买 nike

如何通过列标签属性foreignKeyNamereferences配置外键?我发现的唯一示例演示了 how to add foreign keys after the fact .

最佳答案

使用嵌套的 <constraints>列标签中的标签。

例子:

<changeSet id="SAMPLE_1" author="alice">
<createTable tableName="employee">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true"/>
</column>
<column name="first_name" type="varchar(255)"/>
<column name="last_name" type="varchar(255)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>

<changeSet id="create address table" author="bob">
<createTable tableName="address">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true"/>
</column>
<column name="line1" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="line2" type="varchar(255)"/>
<column name="city" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="employee_id" type="int">
<constraints nullable="false" foreignKeyName="fk_address_employee" references="employee(id)"/>
</column>
</createTable>
</changeSet>

关于java - Liquibase:如何在列标签中设置外键约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24718545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com