What is SQL?
SQL (Structured Query Language) is a standard language used to store, retrieve, manage, and
manipulate data in a relational database.
It is used to create databases, define tables, insert data, update data, delete data, and perform
queries.
SQL is used in RDBMS systems like MySQL, Oracle, SQL Server, PostgreSQL, etc.
---
Syntax for Creating a Table (CREATE TABLE)
General Syntax:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
...
);
Example:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Course VARCHAR(50)
);
Explanation:
CREATE TABLE → Command to create a new table
Students → Name of the table
StudentID INT PRIMARY KEY → Column with integer datatype and primary key
Name VARCHAR(50) → Stores variable-length text up to 50 characters
Age INT → Stores age
Course VARCHAR(50) → Stores course name
---
Syntax for Inserting Data (INSERT INTO)
General Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO Students (StudentID, Name, Age, Course)
VALUES (101, 'Amit', 20, 'BCA');
Explanation:
INSERT INTO Students → Inserts data into the Students table
Column names are listed in order
VALUES (...) → Actual data to be inserted