INSERT
INSERT is a SQL command used to add data into a database table. It allows the user to specify values for all or specific columns within the table. The values are inserted into the table in the order they are provided.
Example
Output
Explanation
The above SQL command INSERT INTO
is used to insert new rows of data into an existing table. In this case, a new customer with customer_id
1, name
‘John Doe’ and city
‘New York’ is inserted into the ‘Customers’ table.
Example
Output
Explanation
In the above INSERT statement, a new row is inserted into the employees
table. The values provided in the statement are ‘1’ for employee_id
, ‘John’ for first_name
, ‘Doe’ for last_name
, and ‘johndoe@example.com’ for email
. The output INSERT 0 1
confirms the statement was executed successfully, and 1 row was inserted.
Example
Output
This operation doesn’t generate any textual output suitable for display.
Explanation
In the provided example, an SQL command is used to insert a new record into a table. The INSERT INTO
statement specifies the table Employee
and the fields: Id
, Name
, Age
, and Department
. The VALUES
keyword followed by a list in parentheses (1, 'John Doe', 32, 'Marketing')
specifies the data to be inserted into the corresponding columns for a new row in the table. As it’s an operation that changes the data, it does not produce any output for display, but if executed successfully, a new row with specified values would be added to the Employee
table.
Example
Output
Explanation
In the above example, a new record is inserted into the employees
table. The INSERT INTO
clause specifies the table, and the list of columns in parentheses indicates where the data will go. The VALUES
clause lists the data to be inserted, which correspond to the listed columns. Each piece of data is separated by a comma within the parentheses.
The TO_DATE
function is used to format the string ‘2022-01-01’ into a date.
The output 1 row inserted.
indicates that the operation was successful and a new record was added to the table.
Example
Output
Explanation
The above SQL code creates a new table ‘Employees’ with five columns including ID, Name, Age, Address, and Salary. Then, it inserts one new row of data into this table. The data consists of an ID of 1, a Name of ‘Tom’, an Age of 25, an Address of ‘123 Street’ and a Salary of 50000.0. The output shows that the operation was successful and one row was affected.