SQL Insert
SQL INSERT statement is a SQL query. It is used to insert a single or multiple records in a table.
There are two ways to insert data in a table:
1. Specify both the column names and the values to be inserted:
2. If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. Here, the “INSERT INTO” syntax would be as follows:
Example
Course Video
NOTE: Practice below practice questions on MSSQL SERVER, it will not execute on site editor.
1. Write A Query to Create Student TABLE with columns StudentID, FirstName, LastName, Age, City AND INSERT 3 RECORDS IN THAT TABLE BY USING COLUMNS.
2. Write SQL Query To insert 2 records into the first two columns of Student table.
3. WRITE QUERY TO INSERT 5 RECORDS IN THAT TABLE WITHOUT MENTIONING COLUMNS.
4. Write a SQL Query To insert Multiple Records (5 records) into a table with a single SQL statement.
5. Create table Workspace with 3 columns Workspace_Id, Workspace_Name, Workspace_Number and insert 10 records in the table.
6. Compose a SQL statement to insert a new record into the Students table, including details for a student with StudentID as 1, FirstName ‘John’, and LastName ‘Doe’.
Output
7. Construct a SQL query to insert multiple student records into the Students table, each featuring unique StudentID, FirstName, and LastName combinations. Specifically, the query should include entries for students with
StudentID 2, FirstName ‘Jane’, and LastName ‘Smith’;
StudentID 3, FirstName ‘Mike’, and LastName ‘Johnson’;
as well as StudentID 4, FirstName ‘Emily’, and LastName ‘Davis’.
8. Compose a SQL statement to add a new student record to the Students table, providing values only for the FirstName and LastName columns, with ‘Alice’ and ‘Brown’ as the respective values.
9. Write a SQL query to insert 3 additional records into the students table without specifying column names.
10. Create a table to store information about various pieces of jewelry.
Design a table named Jewelry with the following columns:
1. Design a table named Jewelry with the following columns:
JewelryID (integer), JewelryName (string), MetalType (string), Gemstone (string), Price (decimal).
2. After creating the Jewelry table, insert 5 records into it with the following details:
- For each record, generate a unique JewelryID.
- Populate JewelryName with names like ‘Diamond Ring’, ‘Gold Necklace’, ‘Sapphire Earrings’, etc.
- Populate MetalType with types like ‘Gold’, ‘Silver’, ‘Platinum’, etc.
- Populate Gemstone with gemstones like ‘Diamond’, ‘Sapphire’, ‘Emerald’, etc.
- Populate Price with prices ranging from 100 to 1000.
Output
YouTube Reference :
1)Introduction to SQL Server in Hindi/Urdu