SQL, or Structured Query Language, is a domain-specific language used for managing and manipulating relational databases. SQL commands are used to perform various tasks, such as querying data, inserting, updating, and deleting records, and managing the structure of a database. Here are some common types of SQL commands with examples:
Data Query Language (DQL): SELECT: Used to retrieve data from one or more tables
SELECT first_name, last_name FROM employees WHERE department = 'HR';
Data Definition Language (DDL):CREATE: Used to create new database objects like tables, indexes, or views.
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
ALTER: Used to modify an existing database structure.
ALTER TABLE customers ADD email VARCHAR(100);
DROP: Used to delete a database object.
DROP TABLE customers;
Data Manipulation Language (DML):INSERT: Used to add new records to a table.
INSERT INTO customers (customer_id, first_name, last_name) VALUES (1, 'John', 'Doe');
UPDATE: Used to modify existing records in a table.
UPDATE customers SET last_name = 'Smith' WHERE customer_id = 1;
DELETE: Used to remove records from a table.
DELETE FROM customers WHERE customer_id = 1;
Data Control Language (DCL):GRANT: Used to give specific privileges to a user or role.
GRANT SELECT ON employees TO user1;
REVOKE: Used to remove privileges from a user or role.
These are fundamental SQL commands used to manage and manipulate data in a relational database. SQL is a powerful tool for interacting with databases, and its commands are crucial for performing various operations on the data and schema of a database.
sql
0 Comments