Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Concepts: Keywords #4747

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions content/mysql/concepts/keywords/keywords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
Title: 'Keywords'
Description: 'MySQL keywords are predefined words that have special meaning in the SQL language and are used to perform various operations within the database.'
Subjects:
- 'Code Foundations'
- 'Data Science'
- 'Data Visualization'
Tags:
- 'MySQL'
- 'Data'
CatalogContent:
- 'learn-sql'
- 'paths/analyze-data-with-sql'
- 'paths/data-science'
- 'paths/data-science-foundations'
---

MySQL **keywords** are predefined words that have special meaning in the SQL language. They are used to perform various operations within the database, such as creating tables, inserting data, querying the database, updating records, and more. Examples of MySQL keywords include SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, and ALTER.

## Importance and Usage

Keywords define the structure and syntax of SQL queries. They help organize the commands in a way that the MySQL database can interpret and execute. Each keyword performs a specific function such as selecting data (`SELECT`), inserting new records (`INSERT`), or modifying existing records (`UPDATE`).
Using keywords ensures that your SQL queries are standarized, this enhances readability and maintainability of your code.
Comment on lines +18 to +23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine and condense these statements. Remove the "Importance and Usage" section and ensure the whole statement is free of redundancy.


## Syntax
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the entire Syntax section. I know I suggested adding it in the last review, and I apologize for any inconvenience this may cause.

Replace it with the following section:

Common MySQL Keywords

Here's a table of some commonly used MySQL keywords along with their definitions:

Keyword Definition
SELECT Retrieves data from one or more tables
FROM Specifies the table(s) to retrieve data from
WHERE Filters the results based on a condition
INSERT Adds new data into a table
UPDATE Modifies existing data in a table
DELETE Removes data from a table
CREATE Creates a new database object (e.g., table, index)
ALTER Modifies the structure of an existing database object
DROP Removes a database object
JOIN Combines rows from two or more tables
GROUP BY Groups rows that have the same values in specified columns
HAVING Specifies a search condition for a group or an aggregate
ORDER BY Sorts the result set in ascending or descending order
LIMIT Specifies the maximum number of rows to return in the result set
UNION Combines the result sets of two or more SELECT statements

Feel free to edit and improve as needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end, please refer to the official documentation of MySQL KEYWORDS for the comprehensive list.


### CREATE

```SQL
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
```

### INSERT

```SQL
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
```

### SELECT

```SQL
SELECT column1, column2, ...
FROM table_name
WHERE condition;
```

### UPDATE

```SQL
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
```

### DELETE

```SQL
DELETE FROM table_name
WHERE condition;
```


## Example

### CREATE

```SQL
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
position VARCHAR(100),
salary DECIMAL(10, 2),
hire_date DATE
);
```

### INSERT

```SQL
INSERT INTO employees (first_name, last_name, position, salary, hire_date)
VALUES ('John', 'Doe', 'Software Engineer', 75000.00, '2024-05-25');
```

### SELECT

```SQL
SELECT first_name, last_name
FROM employees
WHERE position = 'Software Engineer';
```

### UPDATE

```SQL
UPDATE employees
SET salary = 80000.00
WHERE id = 1;
```

### DELETE

```SQL
DELETE FROM employees
WHERE id = 1;
```
Comment on lines +70 to +111
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest combining the use cases of different keywords into one comprehensive example. Like this:

Example

The following example demonstrates the use of several MySQL keywords:

-- Create a new table
CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    position VARCHAR(100),
    salary DECIMAL(10, 2),
    hire_date DATE
);

-- Insert a new employee
INSERT INTO employees (first_name, last_name, position, salary, hire_date)
VALUES ('John', 'Doe', 'Software Engineer', 75000.00, '2024-05-25');

-- Select specific employees
SELECT first_name, last_name
FROM employees
WHERE position = 'Software Engineer';

- Feel free to edit and improve as needed.  
- Wherever possible, Please add the output section.



## Best Practices

**Consistent formatting**: Always write keywords in uppercase for better readability

**Proper naming conventions**: Avoid using keywords as names for tables or coumns. If necessary use, use backticks to avoid syntax errors.

**Comprehensive understanding**: Familiarize yourself with the list of reserved keywors to avoid unintentional errors in yout SQL queries.

Check the complete list [MySQL Documentation](https://dev.mysql.com/doc/refman/8.0/en/keywords.html) for more details!
Loading