Create the data
Add data to the table you just defined by using the following statement
INSERT INTO `my_first_db`.`user` (`id`.`username`.`password`.`ct`) VALUES ('1'.'hq'.'11111'.'the 2018-12-12 12:12:12');
Copy the code
-
The keyword INSERT INTO indicates the insertion
-
My_first_db. user represents the name of the database and the name of the table, for example in Excel and sheet, specifying the target for data insertion
-
What is left is the specific insert data.
-
(`id`, `username`, `password`, `ct`) VALUES (‘1’, ‘hq’, ‘11111’, ‘2018-12-12 12:12:12’); The keyword VALUES in the middle divides the sentence into two paragraphs. The first paragraph is a list of field names and the second paragraph is the value of the field
The instance
INSERT INTO `my_first_db`.`user` (`id`.`username`.`password`.`ct`) VALUES ('1'.'son dragon'.'222222'.'the 2018-11-21 19:12:12');
Copy the code
CP this statement to mysql Workbench, execute it, and see what happens
The result is as follows
17:04:54 INSERT INTO `my_first_db`.`user` (`id`, `username`, `password`, `ct`) VALUES ('1'.'son dragon'.'222222'.'the 2018-11-21 19:12:12') Error Code: 1062. Duplicate entry '1' for key 'PRIMARY'0.000 SECCopy the code
Analyze the above errors
Duplicate entry ‘1’ for key ‘PRIMARY’ 0.000 SEC Error Code: 1062. Duplicate entry ‘1’ for key ‘PRIMARY’ 0.000 SEC Error Code: 1062 is not useful to us. Duplicate entry ‘1’ for key ‘PRIMARY’ 0.000 SEC
Duplicate keyword, ‘for key ‘PRIMARY” Duplicate key, so let’s change 1 to 2 and try again
Modified SQL
INSERT INTO `my_first_db`.`user` (`id`.`username`.`password`.`ct`) VALUES ('2'.'son dragon'.'222222'.'the 2018-11-21 19:12:12');
Copy the code
The following information is displayed:
17:09:22 INSERT INTO `my_first_db`.`user` (`id`, `username`, `password`, `ct`) VALUES ('2'.'son dragon'.'222222'.'the 2018-11-21 19:12:12') 1 Row (s) affected 0.016 SECCopy the code
1 row(s) affected; SQL > alter table affected
Through the following Sql statement
select * from my_first_db.user
Copy the code
But the following information is returned:
17:11:15 select * from user LIMIT 0, 1000 Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list inThe sidebar. 0.000 SECCopy the code
We did not specify the default data, that is, we specified to query the user table in that database
You specify that the execution is the same as the insert statement,
Statement after adding database name:
select * from my_first_db.user
Copy the code
Returns the result
'1'.'hq'.'11111'.'the 2018-12-12 12:12:12'
'2'.'son dragon'.'222222'.'the 2018-11-21 19:12:12'
Copy the code
Insert, applause
Alternatively, if we’re lazy and don’t want to write my_first_db, we can execute the default database: Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar
Let’s do the following:
Double-click the database name to turn black to indicate that the database is the default database
Try downloading SQL without writing the database name
select * from user
Copy the code
You can also return data
’17:21:49 SELECT * from user LIMIT 0, 1000 2 row(s) returned 0.000 SEC / 0.000 SEC’
What if we want to change my password, using the update statement
Modify the data
SQL
We’d like to change your password
update user set password = zlw1314 where id = 1
Copy the code
Update,user is the name of the table, set, password is the value to be changed, equal is the value to be changed, and WHERE is the password to be changed only for the user whose ID is 1.