Mysql database —— Insert data into a table
one , Insert tuple
database :own ->> surface :fruit
->>> Data insertion syntax :
insert into Table name ( Listing 1, Listing 2, Listing 3,...) values( Column value 1, Column value 2, Column value 3,...)
remarks : The column value needs to correspond to the column name one by one
Example 1 :( Insert all data )
# The column name corresponds to the value one by one , The order can be inconsistent with the order in the table insert into fruit(id,name,price,num)
values(1," Banana ",3.11,10);
Example 2 :( Insert partial data )【 Choose according to the columns you need , Most commonly used 】
insert into fruit(name,num) values(" Apple ",10);
Example 3 :( Omit column name to insert data )【 Insert data for all columns by default 】
# Must be 4 Values , One to one correspondence with columns insert into fruit values(3," a mandarin orange ",null,20);
Pay attention :
(1) Non empty columns must be given data
(2) Autoincrement column may not insert data
two , Insert subquery results
->>> Data insertion syntax :
insert into Table name Subquery results
Example 1 :
insert into fruit select * from fruits where price>10;
Example 2 :
insert into fruit(name,num) select name, num from fruits;
Technology