SQL多个外键作为主键

如果我声明下面的表是否隐含地暗示外键都是唯一的主键,还是我需要做更多的事情才能将这两个属性作为主键?
CREATE TABLE Report_has_Items
(
    ReportID int REFERENCES Report(ReportID) NOT NULL,ItemID int REFERENCES Item(ItemID) NOT NULL
)

基本上这两个属性都是来自其他表的外键,它们一起形成一个唯一的键.

解决方法

不,不.上表没有主键.如果要将字段用作主键,请使用:
CREATE TABLE Report_has_Items(
    ReportID int REFERENCES Report(ReportID) NOT NULL,ItemID int REFERENCES Item(ItemID) NOT NULL,PRIMARY KEY (ReportID,ItemID)
)

或类似的东西取决于你的sql dilect.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...