Explain the role of the INSERT statement in SQL with an example.
Explain the role of the INSERT statement in SQL with an example.
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Aryan Kumar
30-Aug-2023Sure. The INSERT INTO statement in SQL is used to insert new rows into a table. The syntax for the INSERT INTO statement is as follows:
The
table_nameis the name of the table that you want to insert the rows into. Thecolumn1,column2,column3, etc. are the names of the columns in the table that you want to insert data into. Thevalue1,value2,value3, etc. are the values that you want to insert into the columns.For example, the following statement would insert a new row into the
productstable with the following values:The
product_idcolumn is the primary key for theproductstable, so it must be unique. Theproduct_nameandproduct_pricecolumns are not constrained, so they can be repeated.The
INSERT INTOstatement can also be used to insert multiple rows into a table at the same time. To do this, you can use a comma-separated list of values for theVALUESclause. For example, the following statement would insert three new rows into theproductstable: