SQLite Create Table

SQLite is a database engine. It does not require any server to process queries. It is a kind of software library that develops embedded software for television, smartphones, and so on. It can be used as a temporary dataset to get some data within the application due to its efficient nature. It is preferable for small datasets.

SQLite CREATE TABLE

SQLite CREATE TABLE is used to create a TABLE in a database. CREATE TABLE helps to create a table in the database with the name of the table and some columns defined in it with constraints, which stores some information. In SQLite, two tables can’t be of the same name.

Syntax:

CREATE TABLE table_name
(column1 datatype KEY Constraints,
column2 datatype,
column3 datatype
.
.
.
columnN datatype)

Example 1:

Let’s understand with the help of examples.

Query:

CREATE TABLE w3wiki
(emp_id varchar(255) PRIMARY KEY,
emp_name varchar(255),
dept varchar(255),
duration varchar(255))

Create w3wiki Table

Explanation:

  • In the above query, We have created a table called w3wiki with the help of CREATE TABLE , which contains the employee_id, employee name, department name, and duration of work.
  • Here we also have used PRIMARY KEY Constraints. PRIMARY KEY ensures that every entry of data in the table is unique. that’s why we implemented this onto employee_id because every employee has a unique ID in the organization.

Example 2:

Let’s insert 2 records and check whether the table is created or not. If the table shows some information, it means our table is created and data is inserted into it otherwise it gives an error.

Query 1

INSERT INTO w3wiki VALUES(01,' Vipul', 'Content', '8 months');
INSERT INTO w3wiki VALUES(02, 'Deepesh', 'Mentor', '16 months');

Query 2

SELECT * FROM w3wiki

After performing INSERT Operation w3wiki Table Look Like

Explanation:

Since our table has been created that’s why the above two INSERT Queries will execute and store the records in it. You can insert any number of records into the table after Creating it and perform any operation once the table has been created.

Conclusion

SQLite is a nimble and serverless database engine ideal for embedded systems and mobile applications. The CREATE TABLE statement allows for easy table creation, as demonstrated with the example of a table named “w3wiki.” The use of PRIMARY KEY ensures unique employee IDs in the table.


Contact Us