Use SQL statement to determine whether the record already exists before insert

Use SQL statement to determine whether the record already exists before insert

Determine whether a record already exists before inserting a SQL statement

INSERT INTO test(A,B) select 'ab',2 
 WHERE NOT EXISTS (SELECT * FROM test WHERE A='ab');

Simple collection of judgments when inserting sql

When the user module or other modules require database uniqueness, you need to first determine whether the data already exists in the database before inserting it;

This is the most basic SQL insert statement.

```sql

```sql
INSERT INTO user(name,password) values(admin,123456)

Next, transform it into inserting to determine whether #{parameter} exists

```sql
INSERT INTO user(name, password)
SELECT #{admin},#{123456}
FROM DUAL WHERE NOT EXISTS
(SELECT name,password
FROM user WHERE name= #{admin} and password= # {123456});
``

This is done, the query return value = 0 means failure = 1 means success

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to check if data exists before inserting in mysql
  • How to implement inserting a record when it does not exist and updating it if it exists in mysql
  • SQL insert into statement writing method explanation
  • MySQL Practical Experience of Using Insert Statement

<<:  The most comprehensive collection of front-end interview questions

>>:  How to draw a vertical line between two div tags in HTML

Recommend

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

Comprehensive explanation of CocosCreator hot update

Table of contents Preface What is Hot Change Coco...

...

Use thead, tfoot, and tbody to create a table

Some people use these three tags in a perverted wa...

Centos7 install mysql5.6.29 shell script

This article shares the shell script of mysql5.6....

How to implement remote access control in Centos 7.4

1. SSH remote management SSH is a secure channel ...

Teach you how to build a Hadoop 3.x pseudo cluster on Tencent Cloud

1. Environmental Preparation CentOS Linux release...

Use simple jQuery + CSS to create a custom a tag title tooltip

Introduction Use simple jQuery+CSS to create a cus...

MySQL incremental backup and breakpoint recovery script example

Introduction Incremental backup means that after ...

JS realizes the front-end paging effect

This article example shares the specific code of ...

Let the web page redirect to other pages after opening for a few seconds

Just add the following code to achieve it. Method ...

Node.js sends emails based on STMP protocol and EWS protocol

Table of contents 1 Node.js method of sending ema...