0% found this document useful (0 votes)
6 views3 pages

DBMS SQL Commands With Examples

The document outlines various SQL commands categorized into Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and Data Control Language (DCL), providing examples for each. It includes commands for creating, altering, and dropping tables, as well as inserting, updating, and deleting data. Additionally, it covers transaction control commands and other useful SQL functions like indexing, grouping, and joining tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

DBMS SQL Commands With Examples

The document outlines various SQL commands categorized into Data Definition Language (DDL), Data Manipulation Language (DML), Transaction Control Language (TCL), and Data Control Language (DCL), providing examples for each. It includes commands for creating, altering, and dropping tables, as well as inserting, updating, and deleting data. Additionally, it covers transaction control commands and other useful SQL functions like indexing, grouping, and joining tables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DBMS SQL Commands with Examples

1. Data Definition Language (DDL)


-- CREATE

CREATE TABLE students (

id INT PRIMARY KEY,

name VARCHAR(50),

age INT

);

-- ALTER

ALTER TABLE students ADD email VARCHAR(100);

-- DROP

DROP TABLE students;

-- TRUNCATE

TRUNCATE TABLE students;

-- RENAME

RENAME TABLE students TO college_students;

2. Data Manipulation Language (DML)


-- INSERT

INSERT INTO students (id, name, age) VALUES (1, 'Rahul', 20);

-- SELECT

SELECT * FROM students;

-- UPDATE

UPDATE students SET age = 21 WHERE id = 1;

-- DELETE

DELETE FROM students WHERE id = 1;


3. Transaction Control Language (TCL)
-- START TRANSACTION

START TRANSACTION;

-- COMMIT

COMMIT;

-- ROLLBACK

ROLLBACK;

-- SAVEPOINT

SAVEPOINT my_savepoint;

-- ROLLBACK TO SAVEPOINT

ROLLBACK TO my_savepoint;

4. Data Control Language (DCL)


-- GRANT

GRANT SELECT, INSERT ON students TO 'user1'@'localhost';

-- REVOKE

REVOKE INSERT ON students FROM 'user1'@'localhost';

5. Other Useful SQL Commands


-- DESC

DESC students;

-- SHOW TABLES

SHOW TABLES;

-- USE

USE my_database;

-- CREATE INDEX

CREATE INDEX idx_name ON students(name);

-- DROP INDEX
DROP INDEX idx_name ON students;

-- GROUP BY

SELECT age, COUNT(*) FROM students GROUP BY age;

-- ORDER BY

SELECT * FROM students ORDER BY name ASC;

-- WHERE

SELECT * FROM students WHERE age > 18;

-- HAVING

SELECT age, COUNT(*) FROM students GROUP BY age HAVING COUNT(*) > 1;

-- JOIN

SELECT s.id, s.name, m.marks

FROM students s

JOIN marks m ON s.id = m.student_id;

You might also like