SQL CREATE TABLE

Article Summary

Creating tables is fundamental β€” tables store your data in rows and columns. πŸ”Ή Basic Syntax πŸ”Ή Example Creates an employees table with 5 columns and constraints. πŸ”Ή Notes by DBMS 🧠 Quick Recap Key Point Explanation Command CREATE TABLE with columns Columns & Data Types Define structure of data Constraints Control data integrity πŸ’‘ […]

Creating tables is fundamental β€” tables store your data in rows and columns.

πŸ”Ή Basic Syntax

CREATE TABLE table_name (
  column1 datatype [constraints],
  column2 datatype [constraints],
  ...
);
  • table_name: Name of your table.
  • column1, column2: Columns with their data types.
  • Constraints like PRIMARY KEY, NOT NULL can be added.

πŸ”Ή Example

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

Creates an employees table with 5 columns and constraints.

πŸ”Ή Notes by DBMS

  • Data types and syntax can slightly vary across DBMS.
  • In Oracle, use NUMBER instead of INT.
  • Add AUTO_INCREMENT (MySQL) or IDENTITY (SQL Server) for auto-generated IDs.

🧠 Quick Recap

Key PointExplanation
CommandCREATE TABLE with columns
Columns & Data TypesDefine structure of data
ConstraintsControl data integrity

πŸ’‘ Always plan table structure carefully before creating it.

Was this helpful?