SQL is a computer language for manipulating databases. It includes possibilities for retrieving and updating data, creating and modifying shapes and tables, but also controlling access to data.
If you are new to SQL (Structured Query Language) commands or need a reminder of some basic commands of this powerful tool, then this article will give you the initial commands.
For the most beginners to say that a database means a collection of formatted data, which can be retrieved through search. This data is essentially like a table with columns and rows. Imagine them as a page in excel where each horizontal bar contains a complete record, divided into columns for easy search and retrieval of only the information you need.
A phone book could be a good example of a database. Imagine in Columns the Names, Address, Telephone and in rows the complete details of each customer.
The handling of such bases is done via the SQL language. The first database management system was RDMBS, developed at MIT in the early 1970s. Since then, Relational Software has undergone many changes in 1979, seeing the usefulness of databases and a language of communication with it. introduced the first available SQL application.
But let's look at its basic commands:
Mandate | Effect |
Query commands | |
SELECT | Choose. It is a basic query command for data recovery |
SELECT * | Using * with SELECT returns all columns |
SELECT column | Specify exact columns by their name |
SELECT table.column | Request a specific column from a specific table |
FROM | Determine where to find the data |
AS | Temporary alias a table name or column, to a new name |
WHERE | Filter results with a condition |
AND | Use multiple conditions with a WHERE clause. The results must correspond to all conditions. |
OR | Use multiple conditions with a WHERE clause. The results must correspond to only one condition |
ORDER BY | Sort the results by one column. The database selects the sorting method |
ORDER BY column ASC | Sort the results by column in ascending order |
ORDER BY column DESC | Sort the results by column in descending order |
LIMIT | Limit the number of results returned |
OFFSET | Ignore the first number of lines. Often used with LIMIT |
SUBQUERY | Run a data retrieval query for another query |
Centralized functions | |
COUNT | Count the number of rows corresponding to the query |
MAX | Show the highest value in a numeric column |
MIN | Show the lowest value in a numeric column |
Add the values of a numeric column | |
AVG | Calculate the average value for a numeric column |
HAVING | Used with aggregate functions instead of the WHERE clause |
GROUP BY | Use to improve the overall result |
Operators | |
LIKE | Search for identical characters for a specific pattern |
DISLIKE | Search for identical characters for a specific pattern (either uppercase or lowercase) |
BETWEEN | Look for a value between two values. Works with dates or numbers |
> | Look for values greater than one condition |
>= | Look for values greater than or equal to one condition |
< | Look for values less than one condition |
<= | Look for values less than or equal to one condition |
= | Look for values that exactly match a situation |
!= | Look for values that are not equal to a condition |
UNITY | Combine two unique questions (with the same columns) into one result |
UNION ALL | Combine two queries (with the same columns) into one result. Duplicates are allowed |
IN | Write with WHERE. Defines multiple OR conditions |
NOTE IN | Write with WHERE. Specifies multiple OR conditions (inverse) or not equal to |
IS NULL | Check for blank values |
IS NOT NULL | Check that there are no blank values |
INTERSECT | Return the results corresponding to two questions |
MINUS | Return results to a query not found in another query |
Creating and editing tables | |
CREATE TABLE | Create a new table |
NULL | Allow empty values for this field |
NOT NULL | Do not allow blank values for this field |
DEFAULT | A default value to fill in a field (unless one is provided) |
AS | Create a new table based on the structure of an existing table. The new table will contain the data from the old table |
ALTER TABLE - ADD COLUMN | Add a new column to an existing table |
ALTER TABLE - DROP COLUMN | Remove a column from an existing table |
ALTER TABLE - ALERT COLUMN | Change the data type of an existing column |
ALTER TABLE - RENAME COLUMN | Rename an existing column |
ALTER TABLE - RENAME TABLE | Rename an existing table |
ALTER TABLE - MODIFY NULL | Allow zero values for a column |
ALTER TABLE - MODIFY NOT NULL | Prevent zero values for a column |
DROP TABLE | Delete a table and all its data |
TRUNCATE TABLE | Delete all data in a table, but not the table itself |
Restrictions | |
PRIMARY KEY | A value that uniquely identifies an entry in a table. A combination of NOT NULL and UNIQUE |
FOREIGN KEY | Indicates a unique value in another table. Often a primary key on the other board |
UNIQUE | Impose unique values for this column per table |
CHECK | Make sure the prices meet a specific condition |
INDEX - CREATE | Optimize tables and significantly speed up queries by adding an index to a column |
INDEX - CREATE UNIQUE | Create an index that does not allow duplicate values |
INDEX - DROP | Remove an index |
Data creation and processing | |
INSERT - SINGLE VALUE | Add a new entry to a table |
INSERT - MULTIPLE VALUES | Add several new entries to a table |
INSERT - SELECT | Add entries to a table, but get the values from an existing table |
UPDATE - ALL | Modify all existing records in a table |
UPDATE - WHERE | Modify existing records in a table that matches a condition |
DELETE - ALL | Remove all entries from a table |
DELETE - WHERE | Remove entries from a table that matches a condition |
SQL is now considered one of the most powerful languages. There are several "dialects" of SQL that differ depending on the database engine. It's a bit like the difference between HD DVD and Blu-ray. SQL is similar between databases, but an occasional composite command may not work exactly the same in all applications.
very good
thank you very much !!!! bravo!