简体   繁体   English

有没有一种方法可以使一个表具有2列的外键引用另外2个表?

[英]Is there a way to have a table having 2 columns that are foreign keys referencing 2 other tables?

I have 3 tables Customer, Store and Receipt. 我有3个表Customer,Store和Receipt。 The Receipt table must have a receiptno which is the primary key. 收据表必须有一个收据编号,它是主键。 Also the Receipt table has attributes customerid and storeid, how to I specify that customerid is a foreign key that references customerid in the customer table AND storeid is a foreign key that references storeid in the Stores table? 另外,收据表还具有customerid和storeid属性,如何指定customerid是在customer表中引用customerid的外键,而storeid是在Stores表中引用storeid的外键?

create table Customer (customerid int primary key);
create table Store    (storeid    int primary key);

create table Receipt  
(
    receiptno  int primary key
   ,customerid int references Customer (customerid)
   ,storeid    int references Store    (storeid)   
 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加主/外键并引用其他表 - Adding primary/foreign keys and referencing other tables 在相互引用的表中具有外键的正确方法是什么 - What is the correct way of have foreign keys in tables that reference each other 一张表有许多其他表的外键可以吗? - Is it fine to have one table with foreign keys to many other tables? SQL外键和引用其他表-一致的错误 - SQL foreign keys & referencing other tables - consistent errors 从具有外键的表中删除到其他表 - delete from table with foreign keys to other tables 多个外键引用其他表中的单个列 - multiple foreign keys referencing single column in other table 当列在其他表 B、C 等中被引用为外键时,SQLite 从表 A 中删除行 - SQLite Delete row from Table A when columns are referenced as FOREIGN KEYS in other Tables B, C, etc 在其他表可以使用连接进行连接时,在单个表中使用多个外键是好还是坏? - Is it good or bad practice to have multiple foreign keys in a single table, when the other tables can be connected using joins? 单表列具有其他单表的多个外键 - Single table column having multiple foreign keys of other single table 当其他表具有外键时,在sqlite中更改列名 - Change column name in sqlite when other tables have foreign keys to it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM