SQLite Create Table

In SQLite, CREATE TABLE statement is used to create a new table. While creating the table, we name that table and define its column and data types of each column.

Syntax:

CREATE TABLE database_name.table_name(  

   column1 datatype  PRIMARY KEY(one or more columns),  

   column2 datatype,  

   column3 datatype,  

   .....  

   columnN datatype,  

); 

    Let’s take an example to create table in SQLite database:

    CREATE TABLE STUDENT(  
    
       ID INT PRIMARY KEY     NOT NULL,  
    
       NAME           TEXT    NOT NULL,  
    
       AGE            INT     NOT NULL,  
    
       ADDRESS        CHAR(50),  
    
       FEES         REAL  
    
    ); 
      SQLite Create table 1

      Use the SQLite “.tables” command to see if your table has been created successfully.

      .tables

      SQLite Create table 2

      Let’s create another table DEPERTMENT for future operations.

      CREATE TABLE DEPARTMENT(  
      
       ID INT PRIMARY KEY      NOT NULL,  
      
        DEPT           CHAR(50) NOT NULL,  
      
        EMP_ID         INT      NOT NULL  
      
      );  

        Now, we have two tables “DEPARTMENT” and “STUDENT”.

        SQLite Create table 3

        Now check the created tables:

        SQLite Create table 4

        Comments

        Leave a Reply

        Your email address will not be published. Required fields are marked *