The following articles mainly describe the actual operation steps of MySQL Data insertion. We often encounter the project of MySQL Data insertion in actual operations, if you want to learn more about the actual operations, you can use the following articles.
Step 1
Using the INSERT statement to INSERT a record is a record for each row in the database table. inserting a record is actually inserting a row into the table)
Format:
- Insert into table_name data table name) VALUES (value 1, value 2, value 3 ...);
The VALUES and character segments in the parentheses following the VALUES keyword must be consistent with the field data type defined in the table you created!
- MySQL (best combination with PHP)> insert into emp values
- -> ('20140901', 'xiaotian ', 100005, '2017-07-10', 'male ');
After successful insertion, the following information is displayed:
- Query OK, 1 row affected (0.03 sec)
Step 2
Check the data in the table to check whether the data has been successfully inserted)
- MySQL (the best combination with PHP)> select * from emp;
After successful insertion, the data is displayed as follows:
- + -------- + ---------- + --------- + ------------ + --------- +
- | Emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
- + -------- + ---------- + --------- + ------------ + --------- +
- | 100005 | Xiaotian | 27 | 3000 | 1979-07-10 | male |
- + -------- + ---------- + --------- + ------------ + --------- +
- 1 row in set (0.00 sec)
Format of one-time insertion of multiple rows: insert into table_name data table name) VALUES (value 1, value 2, value 3 ...), (value 1, value 2, value 3 ...);
- MySQL (best combination with PHP)> insert into emp values
- -> ('20140901', 'hongfeng', 100001, '2017-01-01 ', 'male '),
- -> ('20140901', 'lilay', 100002, '2017-12-31 ', 'fmale ');
You can view the inserted data results:
- + -------- + ---------- + --------- + ------------ + --------- +
- | Emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
- + -------- + ---------- + --------- + ------------ + --------- +
- | 100005 | Xiaotian | 27 | 3000 | 1979-07-10 | male |
- | 100004 | Hongfeng | 29 | 8000 | male |
- | 100002 | Lili | 27 | 7000 | 1979-12-31 | fmale |
- + -------- + ---------- + --------- + ------------ + --------- +
- 3 rows in set (0.00 sec)
The above content is an introduction to MySQL data insertion. I hope you will find some gains.