create database if not exists wsp_test default charset utf8 collate utf8_general_ci
create table if not exists user (
user_id INT() NOT NULL AUTO_INCREMENT,
name varchar() default NULL,
create_time date default NULL,
primary key (user_id)
);
注意点:
默认值是否非空
表类型
主键
自增
常用表字段类型:
int
char
varchar
datetime
double
参考链接:mysql数据类型
修改表字段数据类型
alter table wsp_test change column user_id id int() not null auto_increment;
增加列
alter table user add column descss varchar() default null;
删除列
alter table user drop column descss;
重命名表
alter table user rename to users;
清空表
truncate table users;
insert into users(name) values("小名");
insert into users(name) values("小红");
insert into users(name) values("小白");
insert into users(name) values("小青");
insert into users(name) values("小紫");
update users set name = '小黄' where name = '小白';
update users,salary set salary = salary + salary*percent where salary = ## 连表更新
delete from salary where salary = ;
delete users,salary from users inner join salary on users.id = salary.user_id where salary.salary = ; ## 多表删除