Sqlite Study Notes 4: Create and Delete tables and sqlite Study Notes

Source: Internet
Author: User

Sqlite Study Notes 4: Create and Delete tables and sqlite Study Notes

If you have done so much, isn't it just to get a few tables for data? Let's take a look at how to create a new table.

1. Create a table

The basic syntax is as follows:

CREATE TABLE database_name.table_name(   column1 datatype  PRIMARY KEY(one or more columns),   column2 datatype,   column3 datatype,   .....   columnN datatype,);

Specifically, database_name is your database name. table_name is of course the table name, columnN is the name, PRIMARY_KEY is the primary key, and datatype is the data type of this column.

For example, to create a user table:

CREATE TABLE USER(   ID INT PRIMARY KEY     NOT NULL,   NAME           TEXT    NOT NULL,   AGE            INT     NOT NULL,   ADDRESS        CHAR(50));

# "Not null" indicates that the current Column cannot be blank

After the new table is created, run the following command to view the new table:

.tables
To view the detailed structure of a table, run the following command:

.schema

Ii. delete a table

Run the following command:

DROP TABLE database_name.table_name;






How can I delete table fields in sqlite3? I don't want to delete the table fields in the visual interface. I want to delete the table fields directly by using the command below, but the syntax is incorrect.

Sqlite does not support column deletion. You can do this:
1. Create a publisher_temp table based on the Publisher table (excluding the state_province field)

2. copy the data to publisher_temp.
3. Delete the Publisher table

4. Rename the publisher_temp table

How does sqlite3 delete a specified row of data? (If you want to delete the fifth row of data in a data table)

Delete the fifth row of data in the tmp table
Delete from tmp where rowid in (select rowid from tmp limit 1 offset 4 );
 

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.