当前位置:网站首页>MySQL basic addition, deletion, modification and query exercise
MySQL basic addition, deletion, modification and query exercise
2022-06-09 09:14:00 【Maximize+】
practice 1
# Add, delete, change and check exercises
# Create database dbtest11
CREATE DATABASE IF NOT EXISTS dbtest11 CHARACTER SET 'utf8'
# The following script creates a table my_employees
USE dbtest11;
CREATE TABLE my_employees(
id INT(10),
first_name VARCHAR(10),
last_name VARCHAR(10),
userid VARCHAR(10),
salary DOUBLE(10,2)
);
CREATE TABLE users(
id INT,
userid VARCHAR(10),
department_id INT
);
SHOW TABLES;
# Display table my_employess Structure
DESC my_employees;
DESC users;
# towards my_employees insert data
INSERT INTO my_employees
VALUES(1,'patel','Ralph','Rpatel',895);
SELECT*FROM my_employees;
INSERT INTO my_employees
VALUES
(2,'Dancs','Betty','Bdancs',860),
(3,'Biri','Ben','Bbiri',1100),
(4,'Newman','Chad','Cnewman',750),
(5,'Ropeburn','Audrey','Aropebur',1550);
SELECT*FROM my_employees;
# towards users Insert data into the table
INSERT INTO users VALUES
(1,'Rpatel',10),
(2,'Bdancs',10),
(3,'Bbiri',20),
(4,'Cnewman',30),
(5,'Aropebur',40);
SELECT*FROM users;
# take 3 Of employee No last_name It is amended as follows "drelxer"
UPDATE my_employees
SET last_name = 'drelxer'
WHERE id = 3;
# Reduce all wages to less than 900 The salary of the employee is modified to 1000
UPDATE my_employees
SET salary = 1000
WHERE salary <900;
# take userid by Bbiri Of users Table and my_employees All records in the table are deleted
# The way 1
DELETE FROM my_employees
WHERE userid = 'Bbiri';
DELETE FROM users
WHERE userid = 'Bbiri';
# The way 2
DELETE m,u
FROM my_employees m
JOIN users u
ON m.userid = u.userid
WHERE m.userid = 'Bbiri';
SELECT*FROM my_employees;
SELECT*FROM users;
# Delete my_employees、users Table all data
DELETE FROM my_employees;
DELETE FROM users;
# Check the correction results
SELECT*FROM my_employees;
SELECT*FROM users;
# Empty my_employees
TRUNCATE TABLE my_employees;
# Data cannot be rolled back at this time
practice 2
# Use the existing dbtest11 database
USE dbtest11;
# Create a table pet
CREATE TABLE pet(
NAME VARCHAR(20),
OWNER VARCHAR(20),
species VARCHAR(20),
sex CHAR(1),
birth YEAR,
death YEAR
);
DESC pet;
# Add records
INSERT INTO pet
VALUES
('Fluffy','harold','Cat','f','2003','2010'),
('Claws','gwen','Cat','m','2004',NULL),
('Buffy',NULL,'Dog','f','2009',NULL),
('Fang','beeny','Dog','m','2000',NULL),
('bowser','diane','Dog','m','2003','2009'),
('Chirpy',NULL,'Bird','f','2008',NULL);
SELECT*FROM pet;
# Add fields : The master's birthday owner_birth DATE type
ALTER TABLE pet
ADD owner_birth DATE;
# Name as Claws The owner of the cat is changed to Kevin
UPDATE pet
SET OWNER = 'Kevin'
WHERE NAME = 'Claws'; AND species = 'Cat'
SELECT*FROM pet;
# Change the owner of the undead dog to duck
UPDATE pet
SET OWNER = 'duck'
WHERE death IS NULL AND species = 'Dog';
SELECT*FROM pet;
# Search for pet names without owners
SELECT NAME
FROM pet
WHERE OWNER IS NULL;
# Query dead Cat The name of , master , And the time of death
SELECT NAME,OWNER,death
FROM pet
WHERE death IS NOT NULL AND species = 'Cat';
# Delete the dead dog
DELETE FROM pet
WHERE death IS NOT NULL
AND species = 'Dog';
SELECT*FROM pet;
# Check all pet information
SELECT*FROM pet;
practice 3
# Use existing dbtest11
USE dbtest11;
# establish employee, And add a record
CREATE TABLE employee(
id INT,
NAME VARCHAR(15),
sex CHAR(1),
tel VARCHAR(25),
addr VARCHAR(35),
salary DOUBLE(10,2)
);
INSERT INTO employee(id,NAME,sex,tel,addr,salary)VALUES
(10001,' Zhang Yiyi ',' male ','13456789000',' Qingdao, Shandong ',1001.58),
(10002,' Liu Xiaohong ',' Woman ','13454319000',' Baoding, Hebei ',1201.21),
(10003,' Li Si ',' male ','0751-1234567',' Guangdong foshan ',1004.11),
(10004,' Liu Xiaoqiang ',' male ','0755-5555555',' Guangdong shenzhen ',1501.23),
(10005,' Wang Yan ',' male ','020-1232133',' Guangdong guangzhou ',1405.16);
SELECT * FROM employee;
# Find the salary in 1200~1300 Employee information between
SELECT*FROM employee
WHERE salary BETWEEN 1200 AND 1300;
# Find out the last name " Liu " Employee's job number , full name , Home address
SELECT id,NAME,addr
FROM employee
WHERE NAME LIKE ' Liu %';
# Change Li Si's home address to Shaoguan, Guangdong
UPDATE employee
SET addr = ' Shaoguan, Guangdong '
WHERE NAME = ' Li Si ';
# Find the name with “ Small ” The employees'
SELECT *
FROM employee
WHERE NAME LIKE '% Small %';
About addition, deletion, modification and query
Yes, add, delete, modify, and check JDBC Very common operations , Cooperation after proficiency SELECT Query can flexibly manipulate and modify data at will , Is a very important content .
The following content is Data type refinement 、 constraint 、 View 、 stored procedure
Then there JDBC Technology .
边栏推荐
- 文件排序 (拓展)
- 微信小程序获取用户信息并更新
- 2022-2028 global linear LED lighting industry research and trend analysis report
- Android常见原理性面试题(初步整理)~
- The integrated monitoring system of ankerui distribution room realizes the online monitoring of the environment in the distribution room and ensures the safe operation of the equipment in the distribu
- 3D编程模式:依赖隔离模式
- 安科瑞企业微电网能效管理平台推动电网向能源互联网升级
- [antenna] [2] explanation of some nouns and simple concepts, still
- 2022-2028 global social finance industry research and trend analysis report
- RMAN backup concept_ Consistent and inconsistent RMAN backups
猜你喜欢

HVV blue team points north

Omit 应用 减少 TS 重复代码

安科瑞综合能效管理系统在数据中心的应用

MySQL基础 多表查询

The application of the comprehensive energy efficiency management system of ankery in the data center
![[antenna] [1] explanation of some nouns and simple concepts](/img/bb/49dc431a5302e3cea04e66f8545d02.jpg)
[antenna] [1] explanation of some nouns and simple concepts

安科瑞企业微电网能效管理平台推动电网向能源互联网升级

The fire door monitoring system carries out 24-hour real-time automatic inspection on the status of the fire door

安科瑞Acrel-BUS智能照明控制系统在医院的应用

Qt development -- compilation of serial port assistant
随机推荐
[antenna] [2] explanation of some nouns and simple concepts, still
如何优雅地画一张图
安科瑞企业微电网能效管理平台推动电网向能源互联网升级
Strange things in unit testing
MySQL basic multi table query
neo4j实现社交推荐(四)
RMAN backup concept_ About multiple copies of RMAN backups
远程预付费管理系统帮助物业解决收费难统计难问题
MySQL queries all database table names and their comments
安科瑞Acrel-BUS智能照明控制系统在医院的应用
了解图数据库neo4j(二)
neo4j实现社交推荐(五)
[antenna] [1] explanation of some nouns and simple concepts
Use of cookies, sessions and tokens in web development of system development series
2022-2028 global online code learning industry research and trend analysis report
RMAN backup concept_ Consistent and inconsistent RMAN backups
Project interview questions
Wechat applet to obtain basic user information
Wechat applet obtains user information and updates it
Mock interview plan; Campus simulated interview plan; Job search simulation interview contest plan; Planning book of simulated job hunting competition of School of economics and management; College st