What is SQL? Write the commands of SQL
It looks like you're asking about SQL commands or concepts. SQL (Structured Query Language) is used for managing and manipulating relational databases. Below are some common SQL commands and concepts:
1. **Data Definition Language (DDL):**
- `CREATE`: Used to create a new table, database, index, or view.
```sql
CREATE TABLE Employees (
EmployeeID int,
FirstName varchar(255),
LastName varchar(255),
BirthDate date
);
```
- `ALTER`: Used to modify an existing database object, such as a table.
```sql
ALTER TABLE Employees
ADD COLUMN Email varchar(255);
```
- `DROP`: Used to delete a table, database, index, or view.
```sql
DROP TABLE Employees;
```
2. **Data Manipulation Language (DML):**
- `SELECT`: Used to query and retrieve data from a database.
```sql
SELECT FirstName, LastName FROM Employees WHERE EmployeeID = 1;
```
- `INSERT`: Used to insert new records into a table.
```sql
INSERT INTO Employees (FirstName, LastName, BirthDate)
VALUES ('John', 'Doe', '1980-01-01');
```
- `UPDATE`: Used to modify existing records in a table.
```sql
UPDATE Employees
SET Email = 'john.doe@example.com'
WHERE EmployeeID = 1;
```
- `DELETE`: Used to delete records from a table.
```sql
DELETE FROM Employees WHERE EmployeeID = 1;
```
3. **Data Control Language (DCL):**
- `GRANT`: Used to give a user access privileges to a database.
```sql
GRANT SELECT, INSERT ON Employees TO User1;
```
- `REVOKE`: Used to take back permissions from a user.
```sql
REVOKE SELECT, INSERT ON Employees FROM User1;
```
4. **Transaction Control Language (TCL):**
- `COMMIT`: Used to save the current transaction.
```sql
COMMIT;
```
- `ROLLBACK`: Used to undo the current transaction.
```sql
ROLLBACK;
```
- `SAVEPOINT`: Used to set a savepoint within a transaction.
```sql
SAVEPOINT Savepoint1;
```
5. **Constraints:**
- `PRIMARY KEY`: Uniquely identifies each record in a table.
- `FOREIGN KEY`: Ensures referential integrity for a record in another table.
- `UNIQUE`: Ensures all values in a column are unique.
- `NOT NULL`: Ensures a column cannot have a NULL value.
- `CHECK`: Ensures that the value in a column meets a specific condition.
Would you like more details on a specific SQL command or concept?
Comments
Post a Comment