SQL getting started Tutorial: SQL insert and update simple tutorial
Let's talk about it first.SQL insertTutorial.
The insert statement is used to insert a new record table.
Insert a statement
The insert statement is used to insert a new column into a table.
Database insert syntax
It may be written into two forms.
First, data without specific column names will be inserted, only their values:
INSERT INTO table_nameVALUES (value1, value2, value3,...)
The second form specifies the column name and insert:
INSERT INTO table_name (column1, column2, column3,...)VALUES (value1, value2, value3,...)
Okay. Let's take a look.SQL update.
The UPDATE statement is used to UPDATE the record table.
Update statement
The UPDATE statement is used to UPDATE an existing record table.
Updated SQL syntax
UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_value |
Let's take a look at an update example. Let's look at the table 'A' first'
| _ Id |
LastName |
FirstName |
Address |
City |
| 1 |
Hansen |
Ola |
Timoteivn 10 |
Sandnes |
| 2 |
Svendson |
Tove |
Borgvn 23 |
Sandnes |
| 3 |
Pettersen |
Kari |
Storgt 20 |
Stavanger |
| 4 |
Nilsen |
Johan |
Bakken 2 |
Stavanger |
| 5 |
Tjessem |
Jakob |
|
|
Then execute the following SQL update statement.
UPDATE a SET Address='Nissestien 67', City='Sandnes'WHERE LastName='Tjessem' AND FirstName='Jakob'
| _Id |
LastName |
FirstName |
Address |
City |
| 1 |
Hansen |
Ola |
Timoteivn 10 |
Sandnes |
| 2 |
Svendson |
Tove |
Borgvn 23 |
Sandnes |
| 3 |
Pettersen |
Kari |
Storgt 20 |
Stavanger |
| 4 |
Nilsen |
Johan |
Bakken 2 |
Stavanger |
| 5 |
Tjessem |
Jakob |
Nissestien 67 |
Sandnes |
This is the record we want to update firstname = 'jakob.