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:

snippet
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:

snippet
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.

snippet
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
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +