Add a new field (SQLite) to the table with the ALTER keyword

Source: Internet
Author: User
Tags sqlite


ALTER TABLE

sql-statement:: = ALTER TABLE [database-name . ] table-name alteration

< Span style= "Color:rgb (255,52,52)" >     alteration    :: =   rename to  new-table-name

< Span style= "font-family: Song Body" >     Alteration    :: =   ADD&NBSP; [ COLUMN ] &NBSP; column-def


the SQLite version of the ALTER TABLE command allows the user to rename or add new fields to an existing table and cannot remove fields from the table.

The RENAME to syntax is used to rename the table name [Database-name.] Table-name to new-table-name. This command cannot be used to move tables between attached databases, and tables can only be renamed in the same database.

If the tables that need to be renamed have triggers or indexes, they still belong to the table after renaming. However, if a view is defined, or if the trigger executes a statement that mentions the name of the table, they are not automatically changed to use the new table name. To make this kind of modification, you need to undo it manually and rebuild the trigger or view with the new table name.

The add [COLUMN] syntax is used to add a new field to an existing table. The new field is always added to the end of the existing field list. Column-def can be any form that is allowed in create table and is subject to the following restrictions:

    • A field cannot have a primary key or a unique constraint.
    • Fields cannot have these default values: Current_time, current_date, or Current_timestamp
    • If a NOT NULL constraint is defined, the field must have a non-empty default value.

The ALTER table statement's execution time is independent of the amount of data in the table, which is the same as when you operate a table with 10 million rows, and when you manipulate a table with only one row.

After you run the Add column against the database, the database will not be readable by SQLite 3.1.3 and earlier, unless you run the vacuum command.

More SQLite syntax, see the official website.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.