建表
2019-03-28 本文已影响0人
AAnna珠
create table commdity(
cid int PRIMARY KEY,
cname VARCHAR(20),
cprice DOUBLE);
create table myuser(
uid INT PRIMARY key,
uname varchar(20),
uaddress varchar(20));
create table list(
uid int,
cid int,
amount int,
CONSTRAINT fk_list_myuser FOREIGN key(uid) REFERENCES myuser(uid),
CONSTRAINT fk_list_commdity FOREIGN key(cid) REFERENCES commdity(cid)
);
insert into myuser values(10,'zhang','大连'),(20,'wang','沈阳');
insert into commdity values(11,'计算机',1000.5),(12,'硬盘',100),(13,'显卡',600);
insert into list values(10,11,50),(20,12,5),(20,13,1);
insert into list values(30,11,40);
select commdity.cname,list.amount,myuser.uname
from myuser,list,commdity
where list.uid=myuser.uid
and list.cid=commdity.cid
and myuser.uname='zhang';