Makindo Medical Notes.com |
|
---|---|
Download all this content in the Apps now Android App and Apple iPhone/Pad App | |
MEDICAL DISCLAIMER:The contents are under continuing development and improvements and despite all efforts may contain errors of omission or fact. This is not to be used for the assessment, diagnosis or management of patients. It should not be regarded as medical advice by healthcare workers or laypeople. It is for educational purposes only. Please adhere to your local protocols. Use the BNF for drug information. If you are unwell please seek urgent healthcare advice. If you do not accept this then please do not use the website. Makindo Ltd |
SQL (Structured Query Language) is a standardized programming language used for managing relational databases and performing various operations on the data stored in them. SQL is used to query, insert, update, and delete data, as well as to manage database schema and control access to data.
SELECT column1, column2 FROM table_name WHERE condition;
SELECT first_name, last_name FROM employees WHERE department = 'Sales';
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3);
INSERT INTO employees (first_name, last_name, department) VALUES ('John', 'Doe', 'Sales');
UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
UPDATE employees SET department = 'Marketing' WHERE last_name = 'Doe';
DELETE FROM table_name WHERE condition;
DELETE FROM employees WHERE last_name = 'Doe';
SELECT column1, column2 FROM table1 JOIN table2 ON table1.common_column = table2.common_column;
SELECT employees.first_name, employees.last_name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.department_id;
SELECT column1, COUNT(*) FROM table_name GROUP BY column1;
SELECT department, COUNT(*) FROM employees GROUP BY department;
SELECT column1, column2 FROM table_name ORDER BY column1 [ASC |DESC];
SELECT first_name, last_name FROM employees ORDER BY last_name ASC;
SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > value;
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) > 5;
SELECT AVG(column_name) FROM table_name; SELECT COUNT(column_name) FROM table_name; SELECT SUM(column_name) FROM table_name;
SELECT AVG(salary) FROM employees; SELECT COUNT(*) FROM employees WHERE department = 'Sales'; SELECT SUM(salary) FROM employees WHERE department = 'Sales';
SELECT LENGTH(column_name) FROM table_name; SELECT UPPER(column_name) FROM table_name; SELECT LOWER(column_name) FROM table_name;
SELECT LENGTH(first_name) FROM employees; SELECT UPPER(first_name) FROM employees; SELECT LOWER(last_name) FROM employees;
SELECT CURRENT_DATE; SELECT EXTRACT(YEAR FROM date_column) FROM table_name; SELECT DATEADD(year, 1, date_column) FROM table_name;
SELECT CURRENT_DATE; SELECT EXTRACT(YEAR FROM hire_date) FROM employees; SELECT DATEADD(year, 1, hire_date) FROM employees;
SELECT column1 FROM table_name WHERE column2 = (SELECT column2 FROM table_name WHERE condition);
SELECT first_name, last_name FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name = 'Sales');
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name WHERE condition;
CREATE VIEW SalesEmployees AS SELECT first_name, last_name FROM employees WHERE department = 'Sales';
CREATE INDEX index_name ON table_name (column1, column2);
CREATE INDEX idx_last_name ON employees (last_name);
START TRANSACTION; UPDATE employees SET salary = salary * 1.10 WHERE department = 'Sales'; DELETE FROM employees WHERE last_name = 'Doe'; COMMIT;
START TRANSACTION; UPDATE employees SET salary = salary * 1.10 WHERE department = 'Sales'; COMMIT;
SQL is a powerful language for managing and manipulating relational databases. It provides a wide range of commands and functions for querying, inserting, updating, and deleting data. Advanced features such as joins, subqueries, views, indexes, and transactions enable complex data operations and ensure data integrity and performance. Mastering SQL is essential for database management and development.