如何在hsql create table中使用外键? [英] how to use foreign-keys with hsql create table?
问题描述
有人可以解释一下如何在hsql中使用外键吗?
我想在创建表中使用它,但是工作alter table也可以。
我没有工具,只是在月食中
hsql代码出了什么问题?
could someone explain me how to use foreign keys in hsql? I would like it in an create table, but working alter table is also ok. I am working without tools, just in eclipse whats wrong with the hsql code?
CREATE TABLE user(
t_id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
name VARCHAR(30),
lastname VARCHAR(30),
email VARCHAR(30),
--FOREIGN KEY (b_id) REFERENCES bookingnumber(b_id)
);
CREATE TABLE bookingnumber (
b_id INTEGER PRIMARY KEY
);
ALTER TABLE user
ADD FOREIGN KEY (fk_b_id) REFERENCES bookingnumber(b_id);
推荐答案
也许您正在尝试将每个预订号链接到一个用户。在这种情况下,每个用户可能存在多个预订号。如果要执行此操作,请在BOOKINGNUMBER表中添加一列T_ID并在此表上创建外键。
Perhaps you are trying to link each booking number to a user. In this case, multiple booking numbers may exist for each user. If you want to do this, add a column T_ID to the BOOKINGNUMBER table and created the foreign key on this table.
但是您的声明是将每个用户链接到预订号并且没有正确的语法。它需要USER表中名为B_ID的列才能工作。语法将是这样的:
But your statement is linking each user to a booking number and doesn't have the correct syntax. It needs a column named B_ID in the USER table to work. And the syntax would be like this:
ALTER TABLE user ADD FOREIGN KEY (b_id) REFERENCES bookingnumber(b_id);
这篇关于如何在hsql create table中使用外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!