AUTO_INCREMENT columns are measured automatically, showing NULL (or omitted). To know the value generated may be used after the insertion, LAST_INSERT_ID () which returns the last value created during the current connection. In addition to the INSERT, REPLACE, MySQL offers education, which is an extension to the SQL standard and can replace existing rows with the rows inserted if there is a situation of dual key. In practice, using REPLACE, if you can not insert a row because a PRIMARY KEY or a UNIQUE index already exists on the table, MySQL deletes the old row and insert the new one. This behavior is opposite to that of INSERT IGNORE, with which the new line to be discarded.
To make a REPLACE we have permission to INSERT and DELETE statements, the syntax is almost identical to those of the INSERT, Let's see:
Code:
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name ,...)]
VALUES ({expression | DEFAULT },...),(...),...
or
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
December column_name = {expression | DEFAULT}, ...
or
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name ,...)]
SELECT ...
Another way to insert data into a table that allows us to import a text file: LOAD DATA INFILE. Let's see the syntax:
Code:
LOAD DATA [LOW_PRIORITY | Concurrent] [LOCAL] INFILE 'file_name. Txt'
[REPLACE | IGNORE]
INTO TABLE table_name
[FIELDS
[TERMINATED BY 'string']
[[Optionally] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
[IGNORE number LINES]
[(Name_column_o_variable ,...)]
[SET col_name = expression ,...)]
Bookmarks