Three commonly used statements to insert data in MySQL:
Insert into represents the insertion of data, the database checks the primary key, if there is a repeat error;Replace into represents the insertion of replacement data, a PrimaryKey in the demand table, or a unique index that replaces the new data if the database already exists, if there is no data effect,
In mysql, the insert ignore, insert into, and replace into statements INSERT data INTO the mysql database. What is the difference between them?
The following statements are commonly used in my
Label:Three commonly used statements for inserting data in MySQL:Insert into indicates the data is inserted, the database will check the primary key (PrimaryKey), if there is a repeat error;Replace into represents inserting replacement data, PrimaryKey in the requirements table, or a unique index, if the database already has data, replace with new data, and insert into if no data effects are present;The Replace statement returns a number that indicate
Only recently found that the MySQL INSERT statement has so many uses, here to share.① about INSERT INTO:INSERT INTO table_name values ();INSERT INTO table_name (column) values ();INSERT INTO TABLE_NAME VALUES (select (column) from table_name2);The only thing to be aware of h
What is the difference between insert into, replace into, and insert ignore in MYSQL? mysqlignore
The following statements are commonly used in mysql to insert data:
Insert into indic
all based on the primary key ... The following are the differences between code descriptions, as follows:CREATE TABLE TESTTB (ID int NOT NULL PRIMARY key,name varchar,Age int);INSERT INTO TESTTB (id,name,age) VALUES (1, BB);select * from TESTTB;Insert Ignore into TESTTB (Id,name,age) VALUES (1, "AA");SELECT * from testtb;//is still 1, "BB", 13, because ID is pri
into the table. This means that if you forcibly abort the mysqld (for example, using kill-9)
Or if mysqld stops unexpectedly, all rows that are not written to the disk will be lost.
second, the use of ignore
Ignore is the extension of MySQL relative to standard SQL. If you have duplicate keywords in the new table,
Or, when a warning occurs after the strict mod
The following statements may be used when inserting data into a condition in MySQL, summary. Let's start by building a simple table for testing:CREATE TABLE ' Books ' (' ID ' INT (one) not NULL auto_increment,' Name ' VARCHAR ($) Not NULL,PRIMARY KEY (' id '),UNIQUE KEY ' NewIndex1 ' (' name ')) Engine=innodb DEFAULT Charset=utf8;1.insert Ignore intoWhen data is
This article refers to the link: http://blog.csdn.net/jbboy/article/details/46828917"I think the article is more suitable for learning and reference, it is worth a look"This article to provide you with three kinds of in MySQL to avoid repeated insertion record method, mainly refers to the Ignore,replace,on DUPLICATE key update three methods, you can try to reference.Case one: Using the
This article to provide you with three kinds of in MySQL to avoid repeated insertion record method, mainly refers to the Ignore,replace,on DUPLICATE key update three methods, you can try to reference.Case one: Using the Ignore keywordIf the uniqueness of a record is distinguished by a primary key primary or a unique index, it is possible to avoid duplicate
business logic. But also update some of the most recent values, such as the final check time, the results of the task.
About Insert Ignore
Bottom line: Ignoring the error that occurs when the INSERT statement is executed does not ignore the syntax problem, but ignores the presence of the primary key.
If there is no
Anyone familiar with MySQL may know that MySQL has an "insert ignore" syntax to ignore existing records. PostgreSQL does not currently provide such syntax, but it can be replaced by other methods.
The following shows the sample table structure and data for this demonstratio
generally: only want to save a copy of the data in the database, do not want to duplicate the data (duplicate primary key, unique index), because the duplicate data is not what we want, will cause business logic trouble. But update some fields with the latest values, such as the last check time and the result of the task.The Replace statement returns a number that indicates the number of rows affected. The number is the number of rows that are deleted and inserted, andThe number of rows affecte
This article to provide you with three kinds of in MySQL to avoid repeated insertion record method, mainly refers to the Ignore,replace,on DUPLICATE key update three methods, you can try to reference.Case one: Using the Ignore keywordIf the uniqueness of a record is distinguished by a primary key primary or a unique index, it is possible to avoid duplicate
Label:Some usage summaries of insert ignore into, replace into, etc. in MySQL (GO) The following statements may be used when inserting data into a condition in MySQL, summary. Let's start by building a simple table for testing: CREATE TABLE ' Books ' ( ' ID ' INT (one) not NULL auto_increment, ' Name ' VARCHAR ($) Not
Insert into, replace into, insert ignore, replaceignore
I recently discovered that mysql insert statements have so many usage cases. Here I will share with you.
① Insert:
Insert into ta
CasesInsert Ignore indicates that if the same record already exists, the current new data is ignored;Insert ignore into table (name) select name from Table2CasesINSERT into has no data inserted, if the primary key is not insertedA 1.insert statement can insert multiple sets
Insert into is the most commonly used statement to insert a table, in general, we insert data into the tables to determine whether there is, if it does not exist, insert, and then update the changes. Give me a chestnut ~ ~ ~
If not exists (select 1 from t where id = 1) Then
INSERT
Cases
Insert Ignore indicates that if the same record already exists in, the current new data is ignored;
Insert ignore into table (name) select name from Table2
Cases
Insert into there is no data inserted, if the primary key is not inserted
A 1.
SQLite executes the INSERT or ignore or INSERT or replace statement.Insert or Replace into Values (7,0); Insert or Ignore into Values (7,0);The first statement above is added if it does not exist each time it is executed, and is updated if one exists.The second statement a
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.