Intern
What SQL commands are you familiar with?
sobes.tech AI
Answer from AI
The main SQL commands are divided into several categories:
1. DDL (Data Definition Language) - for defining the database structure:
CREATE: Creating database objects (tables, indexes, views, etc.).CREATE TABLE Customers ( CustomerID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50) );ALTER: Modifying the structure of existing database objects.ALTER TABLE Customers ADD Email VARCHAR(100);DROP: Deleting database objects.DROP TABLE Customers;TRUNCATE: Removing all data from a table while preserving its structure.TRUNCATE TABLE Customers;RENAME: Renaming a database object.ALTER TABLE Customers RENAME TO Clients;
2. DML (Data Manipulation Language) - for working with data:
SELECT: Selecting data from one or more tables.SELECT * FROM Customers WHERE City = 'New York';INSERT: Adding new records to a table.INSERT INTO Customers (CustomerID, FirstName, LastName) VALUES (1, 'John', 'Doe');UPDATE: Modifying existing records in a table.UPDATE Customers SET Email = 'john.doe@example.com' WHERE CustomerID = 1;DELETE: Removing existing records from a table.DELETE FROM Customers WHERE CustomerID = 1;
3. DCL (Data Control Language) - for managing access to data:
GRANT: Granting access rights to database objects.GRANT SELECT ON Customers TO user1;REVOKE: Revoking previously granted access rights.REVOKE SELECT ON Customers FROM user1;
4. TCL (Transaction Control Language) - for managing transactions:
COMMIT: Saving all changes made in the current transaction.COMMIT;ROLLBACK: Canceling all changes made in the current transaction.ROLLBACK;SAVEPOINT: Setting a savepoint within a transaction.SAVEPOINT my_savepoint;
Besides these main commands, there are also various functions, operators, and clauses for more complex data operations (e.g., aggregate functions SUM, AVG, COUNT, comparison operators, logical operators, JOIN, GROUP BY, ORDER BY, HAVING).