SQLite using tutorial 6 to create a table

Source: Internet
Author: User

Http://www.runoob.com/sqlite/sqlite-create-table.html

SqliteCreate a table

The SQLite Create table statement is used for creating a new table in any given database. Create a basic table that involves naming tables, defining columns, and data types for each column.

Grammar

The basic syntax for the CREATE TABLE statement is as follows:

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

  

A CREATE table is a keyword that tells the database system to create a new table. The CREATE table statement is followed by the unique name or identity of the table. You can also choose to specify a database_namewith table_name .

Instance

The following is an instance that creates a company table with an ID as the primary key, and a constraint of NOT NULL indicates that the fields cannot be null when records are created in the table:

Sqlite> CREATE TABLE Company (   ID INT PRIMARY KEY isn't     null,   NAME           TEXT not    null,   age            int< C7/>not NULL,   ADDRESS        CHAR (+),   SALARY         REAL);

Let's create another table, which we'll use in the exercises in the subsequent chapters:

Sqlite> CREATE TABLE DEPARTMENT (   ID INT PRIMARY KEY not      null,   DEPT           CHAR (a) not NULL,   EMP_ ID         INT not      NULL);

You can use the . Tables command in the SQLIte command to verify that the table was created successfully, which lists all the tables in the attached database.

Sqlite>.tablescompany     DEPARTMENT

Here, you can see that the company table appears two times, one is the company table of the main database, and one is the Test.company table for the ' test ' alias created for Testdb.db. You can use the SQLite . Schema command to get the complete information for the table, as follows:

Sqlite>.schema companycreate TABLE Company (   ID INT PRIMARY KEY is not     null,   NAME TEXT is not    null,   Age            INT not     NULL,   ADDRESS        CHAR (+),   SALARY         REAL);

  

SQLite using tutorial 6 to create a table

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.