Mysql add, dele...LOGIN

Mysql add, delete, modify and query insert records

There are two basic syntaxes for inserting records

Inserting basic syntax one

CategoryDetailed explanation
Basic syntaxinsert into table values(value 1, value 2, value n);
ExampleINSERT INTO user values(2,'php中文网','male')
Example descriptionInto the user table The inserted value id is 2, the name is Li Wenkai, and the gender is male

Insert basic syntax two

##CategoryDetailed explanationBasic syntaxinsert into table (field 1, field 2, field n) values ​​(value 1 , value 2, value n);ExampleINSERT INTO user(id,username,sex) values(213,'小Shenyang',1);Example descriptionInsert the id 213 into the user table, the username is Xiaoshenyang, and the gender is 1
Description

The difference between basic syntax 1 and basic syntax 2 is:

    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.
  1. 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.
  2. In basic syntax 2, the order of user(id,username,sex) fields is the order of values.
Assume that there is a table called the user table. We describe the fields, field descriptions, types, and field optional and required states. The table structure is as follows:

FieldidusernameemailpasswordsexNumberUsernameEmailPasswordgenderintvarchar(50)varchar(60)varchar(32)tinyintAuto-incrementRequiredOptional field, the default value is Optional fieldRequired field

Follow Basic Grammar 1Write the insert statement in the table:

INSERT INTO user values(null,'php中文网','pig@php.cn' ,null ,1);

Note

  1. 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.
  2. Fields with default values ​​do not need to be written, then they will be the default values.
  3. 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.
  4. The data format must be consistent with the data format specified in the table.

Write the insert statement in the table according to Basic Grammar 2:

INSERT INTO user(username,sex) values('php Chinese website ',1);

Note

  1. 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.
  2. Fields with default values ​​and nullable fields need not be passed
  3. Subject to the insertion order of table user(username,sex)
  4. Basic syntax 2 is the more common usage

Basic syntax variation: insert multiple records at one time

INSERT INTO user(username,password,sex)
values('Huang Xiaoming', 'abcdef', 1),
('angelababy', 'bcdeef', 0),
('Chen He', '123456', 1),
('Wang Baoqiang', '987654', 1);

Next Section
<?php echo "Hello Mysql"; ?>
submitReset Code
ChapterCourseware
    None
Chinese description
Type description
Default value description123@php.cn