Okay, so in the previous lecture, we have created the table the employees table with the seven columns that we discussed. Next, if we issue a query on this table using the Select all from my staff that employees query, we will see that there are currently zero rows inside this table. So no data has been added yet. In order to insert data into this table, let's see the SQL syntax for this operation. So we have insert into the name of the schema, a dot and then the name of the table. Then inside parentheses, we enter the name of the columns for which we want to insert some data.
Then we have the keyword values. And again in between parentheses, we entered the data to be inserted for each of these columns. If we want to insert more than one row of data into the table, then we can use a comma Ma and open another set of parentheses in which we can specify the data to be inserted on the second row in the table and so on until we insert all the necessary data. Of course, at the end, you shouldn't forget to add the semi colon, which is mandatory for every SQL command. Now translating this into our Python code, this code right here, we've already discussed and tested. Now it's time to use the cursor and execute this insert command.
However, I should mention that the command should be enclosed by quotes. And instead of triple quotes for a command spanning multiple lines we are using after each line, the continuation character backslash, which is used in Python to continue the code on the next line. Finally, of course, we commit our changes and close the connection. Next inside the Python interpreter. I have imported the necessary module I have established the connection created the cursor as we did thus far in the section, there is no need to create the table. Once again, since the table has been already created in the previous lecture, we have committed that change.
And now the table exists in our database. The only thing to do is to copy and paste this command right here in order to insert the data into the table. So let me paste this right here. Enter, the command has been executed. Now it's time to commit the changes once again. So connection dot commit.
And finally connection dot close. And now let's go over to P SQL and query our table once again. And this time you can see that the data inside the insert command has been entered into the table. So for now, we have five employees, each with its own ID, first name, last name, department, phone address, and salary. Okay, so this is the way in which you can insert data into a table Down below immediately after this lecture, you will find the code that we used inside this video so you can copy and paste it inside your Python interpreter or Python applications. I'll see you in the next lecture, where we're going to discuss how to update records in a database.