一、上节内容回购
1、 DBMS(数据库管理系统)
2、mysql 服务端,客户端。
3、通信交流,
创建用户、授权;
发送指令(SQL语句)
4、操作数据库语句
create database db1;
5、数据表语句
创建表语句:
create table userinfo( uid int auto_increment primary key, name varchar(32), department_id int, xx_id int, constraint fk_user_depar foreign key (department_id) references department(id) )engine=innodb default charset=utf8;
create table department( id bigint auto_increment primary key, title char(15) )engine=innodb default charset=utf8;
一张表只能有一个主键;
一个主键可以有两列合起来做主键。
1 create table t1( 2 nid int(11) not null auto_increment, 3 Pid int(11) not null, 4 num int(11) null, 5 primary key (nid,pid) 6 )engnie=innodb default charset=utf8;
create tabel t2( id int auto_increment primary key, name char(10), id1 int, id2 int, constraint fk_t1_t2 foreign key (id1,id2) references t1 (nid,pid) )engnie=innodb default charset=utf8;
create tabel t2( id int auto_increment primary key, name char(10), id1 int, id2 int, constraint fk_t1_t2 foreign key (id1,id2) references t1 (nid,pid) )engnie=innodb default charset=utf8;
6、数据行语句
insert into tb1(name,age) values('chen',18); delete from tb1; truncate tabel tb1; delete from tb1 where id > 10; update tb1 set name='root' where id > 10; select * from tb1; select * from tb1 where id > 10;
自增长
create table t10( nid int(11) not null auto_increment, Pid int(11) not null, num int(11) null, primary key (nid,pid) )engnie=innoDB auto_increment=4 efault charset=utf8; alter table t10 set auto_increment = 2; disc t10; show create table t10; show create table t10 G; alter table t10 set auto_increment = 2;