| MySQL SQL Syntax |
| |
| Insert statement |
| |
| Syntax of Insert statement: |
| |
INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO]
tbl_name [(column_list)]
VALUES (expr [, expr] ...) [, (...)] ... |
| Or |
| |
INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO]
tbl_name [(column_list)]
SELECT ... |
| Or |
| |
INSERT [LOW_PRIORITY | DELAYED] [IGNORE] [INTO]
tbl_name SET col_name=expr [, col_name=expr] ... |
| |
| Inserts rows into an existing table tbl_name and returns the number of rows inserted. The INTO keyword is optional as of MySQL 3.22.5. |
| LOW_PRIORITY causes the statement to be deferred until no clients are reading from the table. LOW_PRIORITY was introduced in MySQL 3.22.5. |
| |
| DELAYED causes the rows to be placed into a queue for later insertion, and the statement returns immediately so that the client can continue on without waiting. However, in this case, LAST_INSERT_ID() will not return the AUTO_INCREMENT value for any AUTO_INCREMENT column in the table. DELAYED inserts were introduced in MySQL 3.22.15; they work only for ISAM and MyISAM tables. |
| |
| If IGNORE is specified, rows that duplicate values for unique keys in existing rows are discarded. If duplicate values occur without IGNORE, an error occurs and no more rows are inserted. IGNORE was introduced in MySQL 3.22.10. |
| |
| The first form of INSERT requires a VALUES() list that specifies all values to be inserted. If no column_list is given, the VALUES() list must specify one value for each column in the table. If a column_list is given consisting of one or more comma-separated column names, one value per column must be specified in the VALUES() list. Columns not named in the column list are set to their default values. As of MySQL 3.22.5, multiple value lists can be specified, allowing multiple rows to be inserted using a single INSERT statement. |
| |
| As of MySQL 3.23.3, the column_list and VALUES() list can be empty, which can be used as follows to create a record for which all columns are set to their default values: |
| |
| INSERT INTO t () VALUES(); |
| |
| As of MySQL 4.0.3, the word DEFAULT can be used in a VALUES() list to set a column to its default value explicitly without knowing what the default value is. |
| |
| The second form of INSERT retrieves records according to the SELECT statement and inserts them into tbl_name. The SELECT statement must select as many columns as are in tbl_name or as many columns as are named in column_list if a column list is specified. When a column list is specified, any columns not named in the list are set to their default values. You cannot select records from the same table into which you are inserting them. |
| |
| The third form of INSERT, available as of MySQL 3.22.10, inserts columns named in the SET clause to the values given by the corresponding expressions. Columns not named are set to their default values. |
| |
| Example: |
| |
| insert into associate_query(associate_name,tid,description) values('R. k. Tiwari ', null, 'Courseware not received ') |
| |
| |
|
|
| |
| |