时间:2021-07-01 10:21:17 帮助过:21人阅读
二、表的创建与数据的插入
用户表 create table user( id int, user varcher(16) not null unique, pwd varcher(32) not null foreign key(group_id) references group(id) ); 用户表的添加 insert into user(user,pwd,group_id) values (‘冬马和纱‘,‘123‘,‘1‘), (‘小母猪雪菜‘,‘123‘,‘1‘), (‘北原春希‘,‘123‘,‘2‘), (‘‘,‘‘,‘‘); 用户组表 create table group( id int primary key auto_increment, group_name varcher(16) ); 多对多表 create table class2teacher( id int primary key auto_increment, class_id int not null, teacher_id int, constraint fk_class foreign key(class_id) references class, constraint fk_teacher foreign key(teacher_id) references teacher, unique(class_id,teacher_id) ); insert into class2teacher(class_id,teacher_id) values (‘‘,‘‘), (‘‘,‘‘);
三、表查询
连表查询 select user.id,user.name,group_name from user inner join group on user.group_id=group.id; 子查询 select user.name from user where group_id in (select id from group where group_name=‘败犬组‘);
MySQL数据命令
标签:pos alter 选择 values sql 删除数据库 insert tab name