SQL_Learning_Guide
SQL_Learning_Guide
1. Introduction to SQL
SQL (Structured Query Language) is a standard programming language used to manage relational databases. It allows
1. DDL (Data Definition Language): Commands that define the structure of a database (e.g., CREATE, ALTER).
2. DML (Data Manipulation Language): Commands to manipulate data (e.g., INSERT, UPDATE, DELETE).
4. TCL (Transaction Control Language): Commands to manage transactions (e.g., COMMIT, ROLLBACK).
5. DCL (Data Control Language): Commands to control access (e.g., GRANT, REVOKE).
Step-by-Step Example:
3. Creating a Table
Command:
name VARCHAR(50),
age INT,
course VARCHAR(50),
admission_date DATE,
city VARCHAR(50)
);
This command creates a student table with columns for ID, name, age, course, admission date, and city.
4. Inserting Data
Command:
INSERT INTO student (id, name, age, course, admission_date, city) VALUES
This command adds a record to the student table. Tip: Always validate your data before inserting it.
Command:
Command:
This command updates the city for the student with ID 1 to 'Delhi'.
Command:
Command:
SQL Learning Guide
Commands:
BEGIN TRANSACTION;
INSERT INTO student (id, name, age) VALUES (3, 'Neha Gupta', 22);
ROLLBACK;
COMMIT;
This example demonstrates how to add a record but rollback the transaction.
Commands:
These commands grant and revoke the SELECT permission on the student table.