The data inside the database is held by the tables. The data can be inserted in these tables either by the queries or even with a straightaway Graphical method. In this tutorial we will see both the methods.
Step 1 – Locating the Appropriate Database
First of all, we need to locate and expand the database where that particular table is present.
After that, expand the table’s directory.
Then we will insert the data in the Inventory table. If we move into the column section, it can be seen that there are four fields which have to be added, namely the ID, the Product Name, the Quantity and the Price.
Step 2 – Writing query for inserting record
Now to insert in table, SQL query would be:
Insert into Inventory (id,Product,quantity,price)
Make sure that each value is separated by a comma. Once done, simply press F5 to execute the query.
At the bottom, in the messages section, a message will appear about table rows that have been affected.
Step 3 – Another Method of Insertion
We can also insert data in a table by simply giving the values straight away.
For that just write the following query:
Insert into Inventory
Make sure that the values in query in SQL inserted into table are in the same order as the order of columns in the table. Now let’s execute this query and in the messages section, you can see the rows that have been affected.
To insert in table, SQL queries are required to be written with much care as error can arise if we just miss to insert ellipsis even.
Step 4 – Viewing Table Data
Now let’s check the table to see if the data has been inserted correctly.
For that let us fetch all records from the inventory table and for that, write:
Select * from inventory
When we execute the query, you can see all the records in the results section below, and they are exactly the same as we mentioned in the query in earlier steps.
Step 5 –Alternate Method of inserting data
To insert in table, SQL provides another way through which we don’t have to write SQL insert into table queries.
For that, just right click on the inventory table and choose the ‘Edit top 200 rows’ option.
Step 6 – Inserting data in Fields
Over here, we can start inserting the data in the table straight away, without using the queries.
All we have to do is type the records in the fields and press enter to save the changes made in each field.
And that is how data is inserted in tables in SQL using insert keyword.