How to delete, modify, and rename a column in SQLite _ MySQL

Source: Internet
Author: User
How to delete, modify, and rename a column bitsCN.com in SQLite

Today, I added a column to the SQLite database. later I found that the column name was wrong. so I used an SQL statement to modify the column name, but it didn't work.

First, discard alter.

Sqlite official instructions are as follows:

SQLite supports a limited subset of alter table. the alter table command in SQLite allows the user to rename a table or to add a new column to an existing table. it is not possible to rename a column, remove a column, or add or remove constraints from a table.

The alter function of sqlite is only a subset of alter table. only some functions are available, such as renaming a table name and adding columns to an existing table.

You cannot rename, delete, or modify an existing column.

After checking N more data, it seems that only one indirect method can be used, whether it is to rename or delete a column.

For example, if the name of the table to be modified is A, follow these steps:

1. create A temporary table T, which has the same columns as Table.

2. insert all data in A Into T using the insert statement.

3. delete Table

4. when creating Table A, the column name of Table A is the result you want. what is the column name you want to modify before? what is this time? A column to be deleted previously, so it is not defined when it is defined.

5. restore data and insert data into A using the insert statement. The structure is insert into A select... from tablen T.

6. delete temporary table T.

This method is too clumsy, but there is no better way yet,

BitsCN.com

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.