【无标题】

SQL语句代码

#创建数据库 chapter 03
create database chapter03;
#删除数据库 chapter04
-- DROP DATABASE chapter04;
#指定使用chapter03数据库
use chapter03;
#创建数据表 员工表 employaees
CREATE table employees(
	EmployeeID char(9),
	Name VARCHAR(50),
	Gender enum('男','女'),
	Age int UNSIGNED,
	JobPosition ENUM('业务经理','开发人员','顾问'),
	Salary decimal(10,2),
	JoinedAt datetime,
	Address TEXT
);
#查看表创建的语句
show create table employees;
/* 查询的 employees表的信息
CREATE TABLE `employees` (
  `EmployeeID` char(9) DEFAULT NULL,
  `Name` varchar(50) DEFAULT NULL,
  `Gender` enum('男','女') DEFAULT NULL,
  `Age` int unsigned DEFAULT NULL,
  `JobPosition` enum('业务经理','开发人员','顾问') DEFAULT NULL,
  `Salary` decimal(10,2) DEFAULT NULL,
  `JoinedAt` datetime DEFAULT NULL,
  `Address` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
*/
#删除表
drop table employees;
#查看表结构
desc employees;
#全部字段插入(插入值必须与表字段值顺序保持一致)
insert into employees values(
  'EMP-00001',
	'张丹',
	'男',
	32,
	'业务经理',
	16000,
	'2016-09-23 10:00:00',
	'南京市'
);
#部分字段插入(插入值必须与指定字段顺序保持一致)
insert into employees(EmployeeID,Name,Gender,Age,JobPosition,Salary,JoinedAt) 
values(
  'EMP-00002',
	'季冉糯',
	'女',
	28,
	'顾问',
	9000,
	'2017-03-16 08:00:00'
);
#全部字段插入(一次性插入多行,最后一行使用分号结尾)
insert into employees values
	( 'EMP-00003','王嘉','男',35,'开发人员',14000,'2018-11-12 14:00:00','北京市'),
	( 'EMP-00004','谭明','男',26,'开发人员',11000,'2018-11-12 14:00:00','上海市'),
	( 'EMP-00005','唐潇','女',27,'开发人员',13000,'2018-11-12 14:00:00','武汉市'),	
	( 'EMP-00006','武鸣','男',25,'开发人员',9000,'2018-11-12 14:00:00','济南市');
	
#部分字段插入(一次性插入多行,最后一行使用分号结尾)
insert into employees(EmployeeID,Name,Gender,Age,JobPosition,Salary,JoinedAt) 
values
	('EMP-00007','赵佳怡','女',23,'顾问',12000,'2017-03-16 08:00:00'),
	('EMP-00008','乌海','女',38,'业务经理',19000,'2017-03-16 08:00:00'),
	('EMP-00009','章节节','男',28,'开发人员',11000,'2017-03-16 08:00:00'),
	('EMP-00010','孔慧语','女',29,'顾问',17000,'2017-03-16 08:00:00');

#------------------------------数据表约束规则
-- (1)NOT NULL ,不为空,设定字段为必填项
use chapter03;
create table employees01(
	EmployeID CHAR(10) NOT NULL,
	Name VARCHAR(50) NOT NULL,
	Gender enum('男','女'),
	Age int unsigned,
	JobPosition enum('业务经理','业务顾问','开发人员','UI设计') NOT NULL,
	JoinedAt datetime,
	salary decimal(10,2),
	Address text 
);
INSERT into employees01 VALUES
	('EMP-00001','孔慧语','女',29,'业务顾问','2017-03-16 08:00:00',17000,'xxxx');

	insert into employees01(EmployeID,name,jobposition) values
	('EMP-00004','AQW','UI设计'),
	('EMP-00005','wAS','业务顾问');
-- (2)default 设置默认值填充。
drop table employees01;
CREATE table employee01(
empID char(10) not null,
name varchar(40) not null,
gender enum('男','女'),
age int unsigned,
jobposition enum('业务经理','业务顾问','开发人员','UI设计') not null,
JoinedAt datetime DEFAULT '2023-05-28 00:00:00',
salary decimal(10,2) DEFAULT 9000,
Address text 
);
insert into employee01(empID,name,jobposition) values
	('EMP-00001','顾语雨','业务顾问'),
	('EMP-00002','雷无桀','业务顾问'),
	('EMP-00003','萧瑟','开发人员');
	
-- (3)UNIQUE 唯一性。
drop table employ02;
use chapter03;
create table employ02(
empID INT NOT NULL unique,
name varchar(30) not null ,
gender enum('男','女'),
jobposition enum('业务经理','业务顾问','开发人员','UI设计') not null,
JoinedAt datetime DEFAULT '2023-05-28 00:00:00',
salary decimal(10,2) DEFAULT 9000,
Address text 
);
insert into employ02(empID,name,jobposition) values
	(01,'顾语雨','业务顾问'),
	(02,'雷无桀','业务顾问'),
	(03,'萧瑟','开发人员');
insert into employ02(empID,name,jobposition) values
	(04,'顾语雨','业务顾问'),
	(05,'雷无桀','业务顾问');
-- (3)Auto_increment自动增长,通常用于序号,数据型字符。
drop table employ02;
use chapter03;
create table employ02(
empID INT unique auto_increment, 
name varchar(30) not null ,
gender enum('男','女'),
jobposition enum('业务经理','业务顾问','开发人员','UI设计') not null,
JoinedAt datetime DEFAULT '2023-05-28 00:00:00',
salary decimal(10,2) DEFAULT 9000,
Address text 
);
insert into employ02(name,jobposition) values
	('顾语雨','业务顾问'),
	('雷无桀','业务顾问'),
	('萧瑟','开发人员');
insert into employ02(name,jobposition) values
	('顾大大','业务顾问'),
	('雷大大','业务顾问');
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值