How to Insert One or More rows in SQLIn this article, we will learn how to insert one or more records in the table of Structured Query Language. The INSERT INTO command in SQL allows the database users to insert one or more records into the SQL table. Following are the two syntaxes for inserting the single row in the table: Syntax 1: This syntax inserts the row in the SQL table by specifying the column names of the table. Syntax 2: In this syntax, we have no need to specify the column names for inserting the row into the SQL table. If you want to insert the record into the table, you have to follow the following steps one by one in the given sequence:
Now, we are going to explain each step with an example: Step 1: Create a DatabaseIn the Structured Query Language, creating a database is the first step for storing the structured tables in the database. Use the following SQL syntax to create a database: Suppose you want to create the School database. For this, you have to type the following command in Structured Query Language: Step 2: Create a Table and Insert the dataNow, you have to use the following syntax for creating the table in the SQL database: Suppose you want to create the Teacher table in the School database. For this, you have to type the following query in your SQL application: Step 3: Insert one row into the tableThe following query inserts the record of only one teacher into the Teacher table: Step 4: View the tableIf you want to view the data of the Teacher table, then you have to write the following query in your SQL application:
Table: Teacher Insert Multiple Rows into the tableIn SQL, you can easily insert more than one row in the table using a single query. The following Insert Into statement inserts the record of five teachers into the Teacher table: To check the result of the above INSERT query, you have to write the following SELECT query in SQL: Output:
Table: Teacher Insert Rows from the SELECT statementIf you want to insert the data of another table in the new table, use the INSERT statement with the SELECT statement. The following statement passes the data of one table into another table: ExampleThe data of the old table is shown in the following table:
Table: Old_Teacher Suppose you have a New_Teacher table whose structure is the same as the Old_Teacher table, and you want to transfer the data of those teachers into the new table from the old table whose address is Delhi. For this operation, you have to use the following INSERT statement with the SELECT query: To check the result of the above query, use the following SELECT statement:
Table: New_Teacher
Next TopicHow to Use LIKE in SQL
|