To add data tables in MySQL, I learned how to add tables today. I wrote a blog to summarize it. PS: after all the annotations are completed on my computer, copy it to the notepad. You can add comments as needed during execution. Select database
Mysql> show databases; # check which databases exist + -------------------- + | Database | + -------------------- + | information_schema | ceshi_ku | mysql | performance_schema | + ------------------ + 4 rows in set (0.00 sec) mysql> use ceshi_ku; # select the database and use it to create a table. it seems that you can select a database instead "; "Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changed
Create a table
Mysql> create table biao-> (-> id int,-> name char (10),-> gender char (2),-> gongsi char (15 ), -> gongzi float->); # Create a simple table with no., name, gender, company, or salary. creating a table is not the focus Currently. it is convenient for the following operations: Query OK, 0 rows affected (0.13 sec) mysql> select * from biao; # view the table content. Currently, the Empty table Empty set (0.00 sec) is used)
Insert data (all columns, multiple rows)
Mysql> insert into biao # select the table to insert-> (id, name, gender, gongsi, gongzi) # insert content to which columns-> values # Start to insert three columns, separated by "," and separated by ";"-> (1, 'ma yun ', 'N', 'Tao bao', 6000.5), # write the content to be inserted in sequence. The order cannot be changed! To correspond one to one-> (2, 'Xiao hong ', 'V', 'Xin lang', 5000.7),-> (3, 'Xiao ming ', 'n ', 'Bai DU', 3000.4); Query OK, 3 rows affected (0.08 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from biao; # View table content, now we will find 3 more lines + ------ + ----------- + -------- + ---------- + -------- + | id | name | gender | gongsi | gongzi | + ------ + ----------- + -------- + ---------- + -------- + | 1 | ma yun | n | tao bao | 6000.5 | 2 | xiao hong | v | xin lang | 5000.7 | 3 | xiao ming | n | bai du | 3000.4 | + ------ + ----------- + -------- + ---------- + -------- + 3 rows in set (0.01 sec)
Insert data (default column, single row)
Mysql> insert into biao # this time, no insert is specified to which columns are inserted. if not, all columns are inserted.-> values-> (4, 'Li Si', 'n ', 'sou Hu', 9000.2); # this operation inserts only one row or multiple rows. you only need to use "," to separate Query OK and 1 row affected (0.07 sec) mysql> select * from biao; # View table content, we will find a row + ------ + ----------- + -------- + ---------- + -------- + | id | name | gender | gongsi | gongzi | + ------ + ----------- + -------- + ---------- + -------- + | 1 | ma yun | n | tao bao | 6000.5 | 2 | xiao hong | v | xin lang | 5000.7 | 3 | xiao ming | n | bai du | 3000.4 | 4 | li si | n | sou hu | 9000.2 | + ------ + ----------- + -------- + ---------- + -------- + 4 rows in set (0.00 sec)
Insert data (specified column, multiple rows)
Mysql> insert into biao-> (id, name, gongsi, gongzi) # this time, not all columns are inserted, but some columns-> values-> (5, 'lao wang ', 'Wang yi', 1000.5), # write them in sequence, remember the corresponding relationship,-> (6, 'Xiao Li', 'Ku gou', 700.1); Query OK, 2 rows affected (0.15 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select * from biao; # View table content. at this meeting, two more rows are found, however, "gender" is null + ------ + ----------- + -------- + ---------- + -------- + | id | name | gender | gongsi | gongzi | + ------ + ----------- + -------- + ---------- + -------- + | 1 | ma yun | n | tao bao | 6000.5 | 2 | xiao hong | v | xin lang | 5000.7 | 3 | xiao ming | n | bai du | 3000.4 | 4 | li si | n | sou hu | 9000.2 | 5 | lao wang | NULL | wang yi | 1000.5 | 6 | xiao li | NULL | ku gou | 700.1 | + ------ + ----------- + -------- + ---------- + -------- + 6 rows in set (0.00 sec)