MySQL
建庫:
create database 庫名::如create database student;
建表案例:
CREATE TABLE `staff` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`name` char(25) NOT NULL,
`sex` int(2) NOT NULL,
`age` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
注意:
engine::表的搜索引擎;
charset::設置表的字符集;
primary key ():設置表的主鍵:
auto_increment:設置自增字段 ;
字段設計簡述:
價格: 字符類型設計爲 decimal(10,2); 10爲十進制,2保留兩位小數
表字段的添加
alter table staff add column post decimal(10,2) not null after age
注:: staff:表名
post:添加的新字段
decimal(10,2) 添加的字段類型
after age:添加在那個字段後面
表字段刪除
alter table staff drop column post