Contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

CREATE TABLE t_bookType(
id int primary key auto_increment,
bookTypeName varchar(20),
bookTypeDesc varchar(200)
);


CREATE TABLE t_book(
id int primary key auto_increment,
bookName varchar(20),
author varchar(10),
price decimal(6,2),
bookTypeId int,
constraint `fk` foreign key (`bookTypeId`) references `t_bookType`(`id`)
);

# 使用数据库
use mybase;

# 实例:建表
create table student(
id int(11) primary key NOT NULL auto_increment,
name varchar(11) default NULL,
sex varchar(7) default NULL,
age int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# 上面的charset一定要加上啊,记得是utf8
# 这样的话就是charset:utf-8和collation:utf8_general_ci


desc t_bookType;

show create table t_bookType;

alter table t_book rename t_book2;


alter table t_book change bookName bookName2 varchar(20);

alter table t_book add testField int first ;

alter table t_book drop testField;

drop table t_bookType;

drop table t_book;
Contents