SQLite Modify Table Structure

Source: Internet
Author: User

The alter table command of SQLite allows you to rename or add new fields to an existing table. fields cannot be deleted from the table.

You can only add columns at the end of the table.

For example, add two columns for subscribe

Alter table subpartition add column activation blob;

Alter table subpartition add column key blob;

You can execute the following statement in a transaction to modify the table.
Change table name to temporary table
Alter table subpartition Rename to _ temp _ subpartition;
Create a new table
Create Table subpartition (orderid varchar (32) primary key, username varchar (32) not null, productid varchar (16) not null );
Import Data
Insert into subpartition select orderid, "", productid from _ temp _ subpartition;
Or
Insert into subpartition () Select orderid, "", productid from _ temp _ subpartition;
Note that double quotation marks (") are used to supplement data that does not exist.
Delete temporary table
Drop table _ temp _ subpartition;


Original article:Http://zhiwei.li/text/2010/06/sqlite-%E4%BF% AE %E6%94%B9%E8%A1%A8%E7%BB%93%E6%9E%84/

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.