create database `company1` default character set utf8 collate utf8_general_ci;
#drop database `company1`;
use `company1`;
# mysqldump -uroot company1 >D:\company1.bak #备份 (-p password)
# mysql -uroot company1 < D:\company1.bak #还原 (-p password)
#==============================================================
drop table if exists `departments`;
CREATE TABLE `departments` (
`id` SERIAL PRIMARY KEY,
`name` NVARCHAR(10) COMMENT '部门名称',
`deleted` BOOLEAN DEFAULT 0
) ENGINE=INNODB COMMENT='部门表';
insert into `departments`(`name`) values
('人事部'),('开发部');
#==============================================================
drop table if exists `employees`;
CREATE TABLE `employees` (
`id` SERIAL PRIMARY KEY,
`department_id` BIGINT UNSIGNED COMMENT '部门ID',
`deleted` BOOLEAN DEFAULT 0
) ENGINE=INNODB COMMENT='雇员表';
insert into `employees`(`department_id`) values
(1),(1),(2),(2);
#==============================================================
drop table if exists `profiles`;
CREATE TABLE `profiles` (
`employee_id` BIGINT UNSIGNED UNIQUE NOT NULL,
`name` NVARCHAR(6) COMMENT '名字',
`gender` BOOLEAN COMMENT '性别',
`age` TINYINT UNSIGNED COMMENT '年龄'
) ENGINE=INNODB COMMENT='雇员简介表';
insert into `profiles`(`employee_id`,`name`,`gender`,`age`) values
(1,'甲',1,29),(2,'乙',0,21),(3,'丙',1,24),(4,'丁',0,32);
MySQL 建表命令
最新推荐文章于 2024-10-07 14:15:35 发布