• iconteach@devfunda.com

Create Table

Create Table

30-08-2025 16:10:42 Time to read : 12 Minutes

The CREATE TABLE command in SQL is used to create a new table in the database.
A table is like a spreadsheet — it stores data in rows (records) and columns (fields).

It lets us specify the table’s name, its columns, the type of data each column can store, and the constraints that maintain the accuracy and integrity of the data.

Let create an employee table

CREATE TABLE employees (
    emp_id INT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50),
    salary NUMERIC(10,2),
    hire_date DATE
);

Explanation:

  • emp_id PRIMARY KEY:  Auto-incrementing ID, unique for each student.
  • first_name VARCHAR(50) NOT NULL: Student name, cannot be empty.
  • last_name VARCHAR(50):  Student last name.
  • salary NUMERIC: Can store values like 45000.50 (10 digits total, 2 after decimal).
  • hire_date DATE: Stores the employee’s joining date.

Show table data:

The SELECT statement is used to retrieve data from a database.

SELECT * FROM employees;
  • * means all columns.
  • Fetches all rows and all columns from the students table.

Show specific column data:

SELECT  emp_id, first_name FROM employees;

 

Want to learn in class