Ad Code

SQL INSERT INTO

SQL INSERT INTO Statement




The SQL INSERT INTO statement is used to insert new rows into a table. The basic syntax of the INSERT INTO statement is as follows:

 

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

 

Here, table_name is the name of the table into which you want to insert new rows. The columns in the table must be specified in parentheses after the table name. Then, the VALUES keyword is used to specify the values to be inserted into each column. The values must be in the same order as the columns.

 For example, if you have a table called employees with columns id, first_name, last_name, email, and hire_date, and you want to insert a new row with the following values:

  

id

first_name

last_name

email

hire_date

1

John

Doe

john.doe@example.com

2022-01-01

 

You would use the following SQL statement:


INSERT INTO employees (id, first_name, last_name, email, hire_date)

VALUES (1, 'John', 'Doe', 'john.doe@example.com', '2022-01-01');


Note that the values for date and time columns must be in a specific format, usually YYYY-MM-DD HH:MM:SS.

You can also insert multiple rows at once using a single INSERT INTO statement by separating each set of values with a comma. For example:


 INSERT INTO employees (id, first_name, last_name, email, hire_date)

VALUES (2, 'Jane', 'Smith', 'jane.smith@example.com', '2022-02-01'),

       (3, 'Bob', 'Johnson', 'bob.johnson@example.com', '2022-03-01');


 This statement will insert two new rows into the employees table with the specified values.

 

 





Post a Comment

0 Comments

Close Menu