CREATE PRIMARY KEY
Let’s understand with the help of an example. Suppose we want to create a table that consists of employee name, employee ID, employee city, and employee department name. If you clearly observe, then you might be thinking in which column you have to apply PRIMARY KEY. So it is very easy, Let me help you in the above table employee’s name can be the same even an employee’s city or department may be the same but every employee has a unique ID. Because it is the only thing that differentiates one employee from another through their IDs.
Syntax:
CREATE TABLE GeekForGeeks
(
emp_id varchar(255) PRIMARY KEY,
emp_name varchhar(255),
emp_city varchar(255),
em_dept varchar(255)
)
Explanation:
We have created a w3wiki table, in which their is a four columns emp_name, emp_city, emp_id and emp_dept where me make emp_id as a PRIMARY KEY because this is the only column that never contains duplicate ID and differentiate each employee based on their employee id.
Since PRIMARY KEY contains UNIQUE entries within it. With the help of PRIMARY KEY, we can easily update or delete the data of any record in the table.
SQLite Primary Key
SQLite is an open-source database system just like SQL database system. It is a lightweight and serverless architecture which means it does not require any server and administrator to run operations and queries. It is widely used by the developer to store the data within the applications. It is preferable for small datasets without much effort. It is used to develop embedded software and run on various operating systems like Windows, Mac OS, and Linux.
Contact Us