Overview
The Insert INTO articulation in SQL is utilized to include modern records to a table in a database. It permits clients to embed one or more rows of information into a table at a time.
The SQL INSERT INTO Statement
A software industry had an issue where they were struggling to keep track of their customers’ orders. Each order had multiple items, and they needed a database to store this data in an efficient manner. The company decided to use the SQL language to create a database. One of the commands they used was the INSERT INTO command. This command allowed them to quickly and easily add data into their database. So, for each customer order, they could add the items that were ordered and their associated information. Lets help them with the syntax and examples.
The SQL Insert INTO Statement is utilized to include unused records in a database table. It includes one or more records to the table and the values that ought to be embedded into each column of the table.
syntax of the statement is as follows:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Example
Table: Employees
sno | FirstName | LastName | Department | Salary |
---|---|---|---|---|
1 | John | Smith | Accounting | 40000 |
INSERT INTO Employees (EmployeeId, FirstName, LastName, Department, Salary)
VALUES (1, 'John', 'Smith', 'Accounting', 40000);
This explanation includes a new record with an EmployeeId of 1, a FirstName of John, a LastName of Smith, an Department of Accounting, and a Salary of 40000. Once this statement is executed, a new row is included to the Employees table with these values.
Insert Data Only in Specified Columns
To insert data into only specified columns, use the following syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Example
CustomerID | CustomerName | City |
---|---|---|
1 | John Smith | New York |
2 | Jane Doe | Los Angeles |
3 | Joe Bloggs | Chicago |
4 | Amy Green | Houston |
INSERT INTO Customers (CustomerID, CustomerName, City)
VALUES (1, 'John Smith', 'New York');
This code is inserting data into the Customers table with only the CustomerID, CustomerName, and City columns being populated. The values of 1, 'John Smith', and 'New York' are being inserted into the columns.
Best Practices to follow while using Insert into statement
Conclusion
This command allowed them to add the items that were ordered, as well as their associated information. With this efficient system, the company was able to keep track of their customer orders in an organized manner. This ensured that their customers were satisfied with the services they received and that the orders were processed accurately and quickly. All in all, the software industry was able to successfully solve their problem with the help of the SQL language and the INSERT INTO command.
Key takeaways
Quiz
1.What command is used to insert a record into a table?
Answer: b. INSERT
2. What is the keyword used in SQL to indicate the values to be inserted in a table?
Answer: b. VALUES
3. What type of data is used to insert new records into a table?
Answer:b. Text
4.What SQL clause is used to specify the columns in a table in which to insert new records?
Answer: d. INTO
Top Tutorials
Related Articles