September 13, 2024
Create Table in SQL
Table creation is very important part in SQL. Without table creation we cannot store data in database. To create a table in SQL, we can use the CREATE TABLE statement, which defines the structure of the table, including table name & column names and their data types. Syntax is below to create a student table
Example
CREATE TABLE student_info(
student_id INT PRIMARY KEY,
first_name VARCHAR(20),
last_name VARCHAR(20),
dob DATE,
class_name VARCHAR(20)
);
Here in above example, as we defined table name as student_info. And student_id is primary key it means each student will have a unique id, it cannot be duplicate. Then we have first_name, last_name and class_name field which are varchar type fields. and dob (date of birth) which as date type field.
For more details about primary key and unique key you can read with this link
Primary Key and Unique Key