MySQL其他篇
目录:
- 1.1 MySQL 三种数据类型(数值,字符串,日期)
- 1.2 MySQL常用增删改查命令
- 1.3 删除,添加或修改表字段
- 1.4 MySQL外键关联(一对多)
- 1.5 MySQL连接查询:两个表之间外键关联
- 1.5 MySQL连接查询:两个表之间外键关联
- 1.6 mysql导入导出
返回顶部
1、数值格式有哪
|
数值型分为两种: 1. 整形 2. 浮点型 |
整形常用有5类 |
非常小的整形 |
1字节:-128~127;0~255 |
Tinyint |
|
较小的整形 |
2字节:-32768~32767 |
Smallint |
||
|
中等大小整形 |
3字节:0~224 |
Mediumint |
||
|
标准整形 |
4字节:0~232 |
int |
||
|
大整形 |
8字节:0~264 |
Bigint |
||
|
浮点型有3类 |
Float(H,D) |
4字节 |
||
|
Double(H,D) |
8字节 |
|||
|
Decinal(H,D)定点数 |
H+2字节 |
|||
2、字符串格式有哪些
|
字符型分为4类 |
Char(n) |
255(固定长度) |
常用于长度不变的(如:性名列)索引快,但浪费空间 |
|
varchar |
255(可变长度) |
节省空间但索引慢 |
|
|
text |
216-1 |
文本数据(文章) |
|
|
blog |
|
二进制数据(相片) |
3、日期型
|
Date(日期) |
YYYY-MM-DD |
|
TIME(时间) |
hh:mm:ss |
|
DATETIME(日期和时间) |
YYYY-MM-DD hh:mm:ss |
|
TIMESTAMP(时间戳) |
YYYYMMDDhhmmss |
|
YEAR(年) |
YYYY |
返回顶部
1、创建数据库和表
1. 创建数据库
mysql> show databases;
mysql> create database tomdb charset utf8; #创建数据库tomdb,使用utf-8做字符编码
mysql> use tomdb #选择使用tomdb数据库
mysql> drop database tomdb;
mysql> show create database tomdb; # 查看创建数据库的语法
2.创建表结构
mysql> show tables
mysql> desc student;
mysql> drop table student;
create table student( id int auto_increment, name char(32) not null, age int not null, register_data date not null, primary key (id)); mysql> create table student( #在tomdb数据库中创建表:student -> id int auto_increment, #在表中创建第一个字段:“id” -> name char(32) not null, #在表中创建第二个字段:“name” -> age int not null, #在表中创建第三个字段:“age” -> register_data date not null, #在表中创建第四个字段:日期 -> primary key (id)); #将表的主键设置为字段:“id Query OK, 0 rows affected (0.10 sec) #这里是创建成功的提示