SQL命令

创建表

create table student(
    student_id int auto_increment,
    student_name varchar(50) not null,
    student_age int not null,
    primary key(student_id)
);
或者
create table student(
    student_id int primary key,
    student_name varchar(50) not null,
    student_age int not null
);

创建带外键约束的表

create table borrow_book(
	borrow_book_id int auto_increment primary key,
	borrow_book_name varchar(100) not null,
	student_id int not null,
	borrow_book_publish varchar(100),
	foreign key(student_id) references student(student_id)
);

 

插入数据

MySql数据库之insert插入语句讲解

insert into student(student_name,student_age) values('张三',22);
insert into student(student_name,student_age) values('李四',23);
insert into student set student_name='赵六',student_age=25;
#一条insert语句插入多条记录
insert into student(student_name,student_age) values('Array',26),('Tina',27),('Ken',28);

 更新数据

MySql数据库之update更新语句讲解

update student set student_name='Tom1' where student_id=1;

 

删除数据

MySql数据库之delete删除语句讲解

delte from timestamp_test where name='aaa';

 删除表中的所有数据

delete from timestamp_test;
或者
truncate table timestamp_test;

 delete和truncate的区别请参见上面的连接。

猜你喜欢

转载自guoying252166655.iteye.com/blog/2075637