当前位置:网站首页>MySQL foundation 05 DML language
MySQL foundation 05 DML language
2022-07-03 01:12:00 【Super brother 1986】
The meaning of database : data storage 、 Data management
Data management method of database :
- adopt SQLyog And other management tools to manage database data
- adopt DML Statement management database data
DML Language : Data operation language
- Used to manipulate data contained in database objects
Include :
INSERT ( Add data statement )
UPDATE ( Update data statement )
DELETE ( Delete data statement )
INSERT command
INSERT INTO Table name [( Field 1, Field 2, Field 3,…)] VALUES(‘ value 1’,‘ value 2’,‘ value 3’)
Be careful :
- Fields or values are separated by commas .
- ’ Field 1, Field 2…’ This part can be omitted , But the added value must be consistent with the table structure , Data columns , The order corresponds to , And the quantity is the same .
- Multiple data can be inserted at the same time , values Separated by commas .
– How to create a foreign key : Create sub table and foreign key
-- Grade table (id\ Grade name )
CREATE TABLE `grade` (
`gradeid` INT(10) NOT NULL AUTO_INCREMENT COMMENT ' grade ID',
`gradename` VARCHAR(50) NOT NULL COMMENT ' Grade name ',
PRIMARY KEY (`gradeid`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
-- Student information sheet ( Student number , full name , Gender , grade , mobile phone , Address , Date of birth , mailbox , ID number )
CREATE TABLE `student` (
`studentno` INT(4) NOT NULL COMMENT ' Student number ',
`studentname` VARCHAR(20) NOT NULL DEFAULT ' anonymous ' COMMENT ' full name ',
`sex` TINYINT(1) DEFAULT '1' COMMENT ' Gender ',
`gradeid` INT(10) DEFAULT NULL COMMENT ' grade ',
`phoneNum` VARCHAR(50) NOT NULL COMMENT ' mobile phone ',
`address` VARCHAR(255) DEFAULT NULL COMMENT ' Address ',
`borndate` DATETIME DEFAULT NULL COMMENT ' Birthday ',
`email` VARCHAR(50) DEFAULT NULL COMMENT ' mailbox ',
`idCard` VARCHAR(18) DEFAULT NULL COMMENT ' ID number ',
PRIMARY KEY (`studentno`),
KEY `FK_gradeid` (`gradeid`),
CONSTRAINT `FK_gradeid` FOREIGN KEY (`gradeid`) REFERENCES `grade`
(`gradeid`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
-- How to add statements using statements ?
-- grammar : INSERT INTO Table name [( Field 1, Field 2, Field 3,...)] VALUES(' value 1',' value 2',' value 3')
INSERT INTO grade(gradename) VALUES (' Freshman ');
-- The primary key increases automatically , Can we omit that ?
INSERT INTO grade VALUES (' Sophomore ');
-- Inquire about :INSERT INTO grade VALUE (' Sophomore ') Error code : 1136
Column count doesn`t match value count at row 1
-- Conclusion :' Field 1, Field 2...' This part can be omitted , But the added value must be consistent with the table structure , Data columns , The order corresponds to , And the quantity is one
Cause .
-- Insert multiple data at a time
INSERT INTO grade(gradename) VALUES (' Junior year '),(' Senior ');
update command
grammar :
UPDATE Table name SET column_name=value [,column_name2=value2,…] [WHERE condition];
Be careful :
- column_name For the data column to change
- value Is the modified data , It can be a variable , Specifically refers to , Expression or nested SELECT result
- condition Filter by , Modify all column data of the table if not specified
Operator :

-- Modify grade information
UPDATE grade SET gradename = ' high school ' WHERE gradeid = 1;
DELETE command
DELETE FROM Table name [WHERE condition];
Be careful :condition Filter by , Delete all column data of the table if not specified
-- Delete the last data DELETE FROM grade WHERE gradeid = 5
TRUNCATE command
effect : Used to completely empty table data , But the table structure , Indexes , Constraints, etc., remain unchanged ;
grammar :
TRUNCATE [TABLE] table_name;
Be careful : The difference in DELETE command
identical : Can delete data , Do not delete table structure , but TRUNCATE Faster, different :
- Use TRUNCATE TABLE To reset AUTO_INCREMENT Counter
- Use TRUNCATE TABLE No impact on transactions ( It will be said after the transaction )
test :
-- Create a test table
CREATE TABLE `test` (
`id` INT(4) NOT NULL AUTO_INCREMENT,
`coll` VARCHAR(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
-- Insert several test data
INSERT INTO test(coll) VALUES('row1'),('row2'),('row3');
-- Delete table data ( No where Conditions of the delete)
DELETE FROM test;
-- Conclusion : If not specified Where Delete all column data of the table , The current value of auto increment is still based on the original value , Will log .
-- Delete table data (truncate)
TRUNCATE TABLE test;
-- Conclusion :truncate Delete data , The auto increment current value will return to the original value and start again ; No logging .
-- Also use DELETE Empty database table data of different engines . After restarting the database service
-- InnoDB : Auto increment column starts again from the initial value ( Because it's stored in memory , If you cut off the power, you will lose )
-- MyISAM : The auto increment column still starts from the previous auto increment data ( In the file , Will not be lost )
边栏推荐
- [C language] branch and loop statements (Part 1)
- Embrace the safety concept of platform delivery
- leetcode:701. 二叉搜索树中的插入操作【bst的插入】
- The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
- 全志A40i/T3如何通过SPI转CAN
- matlab 多普勒效应产生振动信号和处理
- R language uses coin package to apply permutation tests to independence problems (permutation tests, whether response variables are independent of groups, are two numerical variables independent, and
- Rk3568 development board evaluation (II): development environment construction
- Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
- Draw love with go+ to express love to her beloved
猜你喜欢

【FH-GFSK】FH-GFSK信号分析与盲解调研究

全志A40i/T3如何通过SPI转CAN
![[overview of AUTOSAR three RTE]](/img/6a/0df33beb42f165af77a17b5d8b01e2.png)
[overview of AUTOSAR three RTE]

Linear programming of mathematical modeling (including Matlab code)

Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life

Foundations of data science is free to download

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟

Understanding and distinguishing of some noun concepts in adjustment / filtering

拥抱平台化交付的安全理念

数学建模之线性规划(含MATLAB代码)
随机推荐
Esp32 simple speed message test of ros2 (limit frequency)
解决ReactNative使用webView存在缓存问题
1038 Recover the Smallest Number
Embrace the safety concept of platform delivery
按键精灵打怪学习-自动寻路回打怪点
信息熵的基础
【无标题】
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
Linear programming of mathematical modeling (including Matlab code)
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
全志A40i/T3如何通过SPI转CAN
Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
excel去除小数点后面的数据,将数字取整
Matlab Doppler effect produces vibration signal and processing
The difference between relational database and non relational database
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
数据分析思维分析犯法和业务知识——分析方法(一)
Deep analysis of data storage in memory