0% found this document useful (0 votes)
2 views

SQL COMMANDS

SQL commands are essential for interacting with relational databases and are categorized into five types: DDL for defining structures, DML for manipulating data, DQL for querying data, DCL for managing access permissions, and TCL for handling transactions. Each category includes specific commands such as CREATE, INSERT, SELECT, GRANT, and COMMIT, each serving distinct purposes. Overall, SQL commands facilitate comprehensive database management.

Uploaded by

ishimwelukaku08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL COMMANDS

SQL commands are essential for interacting with relational databases and are categorized into five types: DDL for defining structures, DML for manipulating data, DQL for querying data, DCL for managing access permissions, and TCL for handling transactions. Each category includes specific commands such as CREATE, INSERT, SELECT, GRANT, and COMMIT, each serving distinct purposes. Overall, SQL commands facilitate comprehensive database management.

Uploaded by

ishimwelukaku08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

what are the sql commands and it's usage in database?

ChatGPT said:
SQL (Structured Query Language) commands are used to interact with relational
databases. These commands can be categorized into five main types:

1. Data Definition Language (DDL)


DDL commands are used to define and modify database structures such as tables,
schemas, and indexes.

Command Description
CREATE Creates a new table, database, index, or view.
ALTER Modifies an existing database structure (e.g., add, delete, or modify
columns).
DROP Deletes an existing database, table, or view.
TRUNCATE Removes all records from a table but keeps its structure.
RENAME Renames a table or column.
Example:

sql
Copy
Edit
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);
2. Data Manipulation Language (DML)
DML commands are used to manipulate data stored in tables.

Command Description
INSERT Adds new records into a table.
UPDATE Modifies existing records in a table.
DELETE Removes specific records from a table.
Example:

sql
Copy
Edit
INSERT INTO students (id, name, age) VALUES (1, 'John Doe', 20);
UPDATE students SET age = 21 WHERE id = 1;
DELETE FROM students WHERE id = 1;
3. Data Query Language (DQL)
DQL commands are used to retrieve data from databases.

Command Description
SELECT Retrieves data from one or more tables.
Example:

sql
Copy
Edit
SELECT name, age FROM students WHERE age > 18;
4. Data Control Language (DCL)
DCL commands are used to manage access permissions.

Command Description
GRANT Gives user-specific privileges.
REVOKE Removes user-specific privileges.
Example:

sql
Copy
Edit
GRANT SELECT, INSERT ON students TO user1;
REVOKE INSERT ON students FROM user1;
5. Transaction Control Language (TCL)
TCL commands manage database transactions.

Command Description
COMMIT Saves all changes made in the transaction permanently.
ROLLBACK Reverts changes made in the transaction.
SAVEPOINT Sets a savepoint within a transaction for partial rollbacks.
Example:

sql
Copy
Edit
BEGIN TRANSACTION;
UPDATE students SET age = 22 WHERE id = 1;
SAVEPOINT sp1;
DELETE FROM students WHERE id = 2;
ROLLBACK TO sp1;
COMMIT;
Conclusion
SQL commands help in database management, ranging from defining structures (DDL),
manipulating data (DML), querying records (DQL), controlling access (DCL), and
managing transactions (TCL).

You might also like