SQLite Quick Start 2-create, modify, and delete tables and views

Source: Internet
Author: User

Create, modify, and delete tables, views, and indexes

I. Table Creation

1. Create a table

Create if not exists table student (stuid integer );

2. Create a data table with default values:

Create Table if not exists schooltable (schid integer default 0, schname varchar default 'hz ');

3. Use if not exists

If the table name, view name, and index name already exist, this creation operation will fail. If not exists clause is added, this creation operation will not be affected.

Create Table if not exists studenttest (stuid integer );

4. Primary Key

Create Table if not exists studenttable (stuid integer primary key ASC); Create a primary key

Create Table if not exists studenttable2 (stuid integer, stuname varchar, primary key (stuid, stuname); create a joint primary key

4 unique constraints

Create Table if not exists suttest (stuid integer unique); Create a uniqueness Constraint

5 check Constraints

Create Table if not exists suttest2 (stuid integer, Id integer, check (stuid> 0 and ID <0 ));

 

Ii. Table Modification

1. Modify the table name

Alter table susutest Rename to stutest;

2. Add a new column to the table

Alter table stutest add column stuname varchar;

 

Iii. Table Deletion

Drop table if exists stutest if a table is deleted, the related indexes and triggers are also deleted.

 

4. Create a view

1. Create a simple view

Create view if not exists view_effecate as select * From effecate where corid> 1

2. Create a temporary View

Create temp view tempview_cmdate as select * From cmdate where corid> 1

 

5. delete a view

Drop view if exists view_gateate;

 

6. Create an index

1. The index is based on the corid field of the replicate table.

Create index cor_index on duplicate ate (corid );

2. The index is based on the corid and corname fields of the replicate table and specifies the sorting rules for each field.

Create index cor_index2 on marshate (corid ASC, corname DESC );

3. Create a unique index

Create unique index cor_index3 on duplicate ate (corid ASC, corname DESC );

 

7. delete an index

Drop index if exists cor_index3;

 

8. reindex reconstruction;

Re-indexing is used to delete an existing index and re-indexing the index based on its original rules.

9. Data Analysis analyze;

10. Vacuum;

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.