Mysql add, delete, modify and query insert records
There are two basic syntaxes for inserting records
Inserting basic syntax one
Category | Detailed explanation |
---|---|
Basic syntax | insert into table values(value 1, value 2, value n); |
Example | INSERT INTO user values(2,'php中文网','male') |
Example description | Into the user table The inserted value id is 2, the name is Li Wenkai, and the gender is male |
Insert basic syntax two
Detailed explanation | |
---|---|
insert into table (field 1, field 2, field n) values (value 1 , value 2, value n); | |
INSERT INTO user(id,username,sex) values(213,'小Shenyang',1); | |
Insert the id 213 into the user table, the username is Xiaoshenyang, and the gender is 1 |
-
In the insert statement of basic syntax 1, as many values as there are fields in the table must be inserted. No one can be more, and no one can be less. If there is a default value and you don’t want to pass it, you can write null.
In basic syntax 2, unless there are required fields, values must be written. If you don't want to write a default value, you can ignore it. mysql will automatically supplement the default value.
In basic syntax 2, the order of user(id,username,sex) fields is the order of values.
FollowBasic Grammar 1Write the insert statement in the table:
INSERT INTO user values(null,'php中文网','pig@php.cn' ,null ,1);
Note
- You don’t have to specify the field name, but the order after the values should be consistent with the sorting of the table fields.
- Fields with default values do not need to be written, then they will be the default values.
- If there is a default value or a nullable field and you do not want to pass in a specific value, you can write null.
- The data format must be consistent with the data format specified in the table.
Write the insert statement in the table according toBasic Grammar 2:
INSERT INTO user(username,sex) values('php Chinese website ',1);
Note
- You don’t need to pass in a value if the ID is auto-incremented. The value of this field is inserted every time It will automatically increase by 1.
- Fields with default values and nullable fields need not be passed
- Subject to the insertion order of table user(username,sex)
- Basic syntax 2 is the more common usage
Basic syntax variation: insert multiple records at one time
Continuing LearningINSERT INTO user(username,password,sex)
values('Huang Xiaoming', 'abcdef', 1),
('angelababy', 'bcdeef', 0),
('Chen He', '123456', 1),
('Wang Baoqiang', '987654', 1);
- Course Recommendations
- Courseware download
-
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watching -
ElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watching -
IntermediateIssue 22_Comprehensive actual combat
5521 people are watching -
ElementaryIssue 22_PHP Programming
5172 people are watching -
ElementaryIssue 22_Front-end development
8713 people are watching -
IntermediateBig data (MySQL) video tutorial full version
4525 people are watching -
ElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watching -
ElementaryGO Language Core Programming Course
2814 people are watching -
IntermediateJS advanced and BootStrap learning
2563 people are watching -
IntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watching -
IntermediateRedis+MySQL database interview tutorial
2963 people are watching -
ElementaryDeliver food or learn programming?
5708 people are watching
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
id | username | password | sex | ||
---|---|---|---|---|---|
Chinese description | NumberUsername | Password | gender | ||
Type description | intvarchar(50) | varchar(60) | varchar(32) | tinyint | |
Default value description | Auto-incrementRequired | Optional field, the default value is | 123@php.cn | Optional fieldRequired field |