如何将 table 的记录分配给外键
How to assign records of a table to a foreign key
我有两个 tables vehicles
和 markers
。我将 table vehicles
的 ID veh_id
作为外键放入 markers
table 。我在 vehicles
table 中只有两条记录。
我想将 markers
table 的 30 条记录分配给 veh_id
.
我尝试了很多但没有成功。
谢谢
在创建 table 或更新 table 标记 table
查询中使用以下行
CONSTRAINT foreign_vehid FOREIGN KEY(veh_id) REFERENCES vehicles(veh_id);
为了这个工作;这两个字段 (veh_id) 应该具有共同的数据类型。
如果你想设置默认值value/null,语法如下:
[CONSTRAINT c_name]
[[FOREIGN KEY] ({col_name1} ,...)]
REFERENCES table_name ({col_name2},...)
[ON DELETE {NO ACTION| CASCADE | SET NULL | SET DEFAULT}]
[ON UPDATE {NO ACTION | CASCADE | SET NULL | SET DEFAULT}]
我有两个 tables vehicles
和 markers
。我将 table vehicles
的 ID veh_id
作为外键放入 markers
table 。我在 vehicles
table 中只有两条记录。
我想将 markers
table 的 30 条记录分配给 veh_id
.
我尝试了很多但没有成功。 谢谢
在创建 table 或更新 table 标记 table
查询中使用以下行CONSTRAINT foreign_vehid FOREIGN KEY(veh_id) REFERENCES vehicles(veh_id);
为了这个工作;这两个字段 (veh_id) 应该具有共同的数据类型。
如果你想设置默认值value/null,语法如下:
[CONSTRAINT c_name]
[[FOREIGN KEY] ({col_name1} ,...)]
REFERENCES table_name ({col_name2},...)
[ON DELETE {NO ACTION| CASCADE | SET NULL | SET DEFAULT}]
[ON UPDATE {NO ACTION | CASCADE | SET NULL | SET DEFAULT}]