摘要
- 加分号
- create database if not exists []
- insert into student value
- update student set age = 11
- alter table student add/change/modify
1. 创建数据库(scheme)
create databases if not exists practice1;
- 不能忘记加分号
- if not exists 是在中间,且是exists
2. 创建数据表(table)
create table if not exists student(
firstname varchar(30) not null,
lastname varchar(30) not null,
ID varchar(5) not null,
Age int not null,
primary key (ID)
);
是用() 而不是{}
同样在数据库下 table data import wizard 可以导入一个table 运行sql后可将结果输出至csv3. 查看信息
describe student;
select * from student;
4. 赋值
INSERT INTO student VALUE ('Harry', 'Truman', '12345', 12);
INSERT INTO student VALUE ('Shelly', 'Johnson', '12346', 13);
INSERT INTO student VALUE ('Joe', 'White', '12347', 14);
INSERT INTO student VALUE ('Charlie', 'Brown', '12348', 15);
5.改值
update student set Age = 11
where ID = '12345' ;#ID是varchar
6. 增加一列删除一列
alter table student add state varchar(5);
alter table student add column state varchar(20) not null after gg;
alter table student add column state varchar(20) first;
alter table student drop state;
7. 改名字改类型
alter table student change ID student_id varchar(5);
alter table student change `ID` `student_id`Varchar(5) ;
alter table student modify ID varchar(10);
- change了之后要跟上student_id 的类型
- 要么 ``
student_ID
Varchar(5)
8. 删表
drop table student;
网友评论