Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use the special INSERT statement in SQLite

Shulou Source: shulou.com Published: 2022-05-31 12:32:55 10月22日 Update

Editor to share with you how to use the special INSERT sentence in SQLite. I hope you will get something after reading this article. Let's discuss it together.

Special INSERT statement in SQLite

In SQLite, INSERT is the basic statement used to insert data into a table. However, when there are unique, non-empty, check, primary key and other constraints in the fields in the table, the inserted data can easily conflict with the constraints, resulting in the failure of the insert operation. To solve this problem, SQLite provides centralized special INSERT statements. The following is introduced in turn:

(1) INSERT OR REPLACE statement: if a constraint conflict occurs, cancel the insert operation. If it conflicts with a unique, primary key constraint, the existing data is updated. If you are operating with a non-null constraint and there is a default setting, replace the conflicting empty column with the default value and insert it; otherwise, follow the INSERT OR ABORT method. If it conflicts with the check constraint, follow INSERT OR ABORT.

(2) INSERT OR ABORT statement: if a constraint conflict occurs, cancel the insert operation. If in a transaction, the current transaction is not rolled back, the subsequent operation of the current transaction continues.

(3) INSERT OR ROLLBACK statement: if a constraint conflict occurs, cancel the insert operation. If you are in a transaction, the current transaction is rolled back.

(4) INSERT OR FAIL statement: if a constraint conflict occurs, cancel the insert operation. If you are in a transaction, the current transaction is not rolled back, but subsequent operations of the current transaction are canceled.

(5) INSERT OR IGNORE statement: if a constraint conflict occurs, cancel the insert operation. If in a transaction, the current transaction is not rolled back, the subsequent operation of the current transaction continues. Unlike INSERT OR ABORT, it does not trigger SQLITE_CONSTRAINT errors.

After reading this article, I believe you have a certain understanding of "how to use special INSERT sentences in SQLite". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Transactions statements conflicts special data articles checks differences fields done ways more knowledge industry information information channels errors problems channels updates Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Shulou Technology Microsoft vpn