remove non ascii whitespaces

This commit is contained in:
JMARyA 2024-01-17 09:44:04 +01:00
parent 598a10bc28
commit 5a6d6c4d13
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
117 changed files with 1928 additions and 1928 deletions

View file

@ -20,7 +20,7 @@ git config --global user.email "johndoe@example.com"
```
## Usage
A Git repository is contained in a `.git` directory, which holds the revision history and other metadata. The directory tracked by the repository, by default the parent directory, is called the working directory. Changes in the working tree need to be staged before they can be recorded (committed) to the repository. Git also lets you restore, previously committed, working tree files.
A Git repository is contained in a `.git` directory, which holds the revision history and other metadata. The directory tracked by the repository, by default the parent directory, is called the working directory. Changes in the working tree need to be staged before they can be recorded (committed) to the repository. Git also lets you restore, previously committed, working tree files.
### Git repository
Initialize a repository
@ -32,7 +32,7 @@ git init -b main
Clone an existing repository
```shell
git clone repository
git clone repository
git clone repository folder
git clone --recursive repository
git clone --bare repository
@ -125,7 +125,7 @@ git checkout master
git merge branch
```
The changes will be merged if they do not conflict. Otherwise, Git will print an error message, and annotate files in the working tree to record the conflicts. The annotations can be displayed with `git diff`. Conflicts are resolved by editing the files to remove the annotations, and committing the final version.
The changes will be merged if they do not conflict. Otherwise, Git will print an error message, and annotate files in the working tree to record the conflicts. The annotations can be displayed with `git diff`. Conflicts are resolved by editing the files to remove the annotations, and committing the final version.
Any conflicts will look something like this:
```

View file

@ -8,7 +8,7 @@ GitHub Actions is a continuous integration and continuous delivery (CI/CD) platf
GitHub Actions goes beyond just DevOps and lets you run workflows when other events happen in your repository. For example, you can run a workflow to automatically add the appropriate labels whenever someone creates a new issue in your repository.
You can configure a GitHub Actions _workflow_ to be triggered when an _event_ occurs in your repository, such as a pull request being opened or an issue being created. Your workflow contains one or more _jobs_ which can run in sequential order or in parallel. Each job will run inside its own virtual machine _runner_, or inside a container, and has one or more _steps_ that either run a script that you define or run an _action_, which is a reusable extension that can simplify your workflow.
You can configure a GitHub Actions _workflow_ to be triggered when an _event_ occurs in your repository, such as a pull request being opened or an issue being created. Your workflow contains one or more _jobs_ which can run in sequential order or in parallel. Each job will run inside its own virtual machine _runner_, or inside a container, and has one or more _steps_ that either run a script that you define or run an _action_, which is a reusable extension that can simplify your workflow.
Example:
```yml
@ -37,7 +37,7 @@ jobs:
## Expressions
You can use expressions to programmatically set [environment variables](../linux/Environment%20Variables.md) in workflow files and access contexts. An expression can be any combination of literal values, references to a context, or functions. You can combine literals, context references, and functions using operators.
Expressions are commonly used with the conditional `if` keyword in a workflow file to determine whether a step should run. When an `if` conditional is `true`, the step will run.
Expressions are commonly used with the conditional `if` keyword in a workflow file to determine whether a step should run. When an `if` conditional is `true`, the step will run.
You need to use specific syntax to tell [GitHub](GitHub.md) to evaluate an expression rather than treat it as a string.
`${{ <expression> }}`
@ -49,35 +49,35 @@ Secrets passed to GitHub Actions can be used:
#### contains
`contains( search, item )`
Returns `true` if `search` contains `item`. If `search` is an array, this function returns `true` if the `item` is an element in the array. If `search` is a string, this function returns `true` if the `item` is a substring of `search`. This function is not case sensitive. Casts values to a string.
Returns `true` if `search` contains `item`. If `search` is an array, this function returns `true` if the `item` is an element in the array. If `search` is a string, this function returns `true` if the `item` is a substring of `search`. This function is not case sensitive. Casts values to a string.
#### startsWith
`startsWith( searchString, searchValue )`
Returns `true` when `searchString` starts with `searchValue`. This function is not case sensitive. Casts values to a string.
Returns `true` when `searchString` starts with `searchValue`. This function is not case sensitive. Casts values to a string.
#### endsWith
`endsWith( searchString, searchValue )`
Returns `true` if `searchString` ends with `searchValue`. This function is not case sensitive. Casts values to a string.
Returns `true` if `searchString` ends with `searchValue`. This function is not case sensitive. Casts values to a string.
#### format
`format( string, replaceValue0, replaceValue1, ..., replaceValueN)`
Replaces values in the `string`, with the variable `replaceValueN`. Variables in the `string` are specified using the `{N}` syntax, where `N` is an integer. You must specify at least one `replaceValue` and `string`. There is no maximum for the number of variables (`replaceValueN`) you can use. Escape curly braces using double braces.
Replaces values in the `string`, with the variable `replaceValueN`. Variables in the `string` are specified using the `{N}` syntax, where `N` is an integer. You must specify at least one `replaceValue` and `string`. There is no maximum for the number of variables (`replaceValueN`) you can use. Escape curly braces using double braces.
#### always
Causes the step to always execute, and returns `true`, even when canceled. The `always` expression is best used at the step level or on tasks that you expect to run even when a job is canceled. For example, you can use `always` to send logs even when a job is canceled.
Causes the step to always execute, and returns `true`, even when canceled. The `always` expression is best used at the step level or on tasks that you expect to run even when a job is canceled. For example, you can use `always` to send logs even when a job is canceled.
Example of `always`:
Example of `always`:
```yaml
if: ${{ always() }}
```
#### failure
Returns `true` when any previous step of a job fails. If you have a chain of dependent jobs, `failure()` returns `true` if any ancestor job fails.
Returns `true` when any previous step of a job fails. If you have a chain of dependent jobs, `failure()` returns `true` if any ancestor job fails.
Example of `failure`:
Example of `failure`:
```yaml
steps:
...
@ -89,25 +89,25 @@ steps:
## Workflows
A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a [YAML](../files/YAML.md) file checked in to your repository and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule.
Workflows are defined in the `.github/workflows` directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks. For example, you can have one workflow to build and test pull requests, another workflow to deploy your application every time a release is created, and still another workflow that adds a label every time someone opens a new issue.
Workflows are defined in the `.github/workflows` directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks. For example, you can have one workflow to build and test pull requests, another workflow to deploy your application every time a release is created, and still another workflow that adds a label every time someone opens a new issue.
### Syntax
#### `name`
The name of the workflow. [GitHub](GitHub.md) displays the names of your workflows under your repository's "Actions" tab. If you omit `name`, [GitHub](GitHub.md) displays the workflow file path relative to the root of the repository.
The name of the workflow. [GitHub](GitHub.md) displays the names of your workflows under your repository's "Actions" tab. If you omit `name`, [GitHub](GitHub.md) displays the workflow file path relative to the root of the repository.
#### `on`
To automatically trigger a workflow, use `on` to define which events can cause the workflow to run.
To automatically trigger a workflow, use `on` to define which events can cause the workflow to run.
You can define single or multiple events that can trigger a workflow, or set a time schedule. You can also restrict the execution of a workflow to only occur for specific files, tags, or branch changes. These options are described in the following sections.
**Using a single event:**
For example, a workflow with the following `on` value will run when a push is made to any branch in the workflow's repository:
For example, a workflow with the following `on` value will run when a push is made to any branch in the workflow's repository:
```yaml
on: push
```
**Using multiple events:**
You can specify a single event or multiple events. For example, a workflow with the following `on` value will run when a push is made to any branch in the repository or when someone forks the repository:
You can specify a single event or multiple events. For example, a workflow with the following `on` value will run when a push is made to any branch in the repository or when someone forks the repository:
```yaml
on: [push, fork]
```
@ -115,9 +115,9 @@ on: [push, fork]
If you specify multiple events, only one of those events needs to occur to trigger your workflow. If multiple triggering events for your workflow occur at the same time, multiple workflow runs will be triggered.
**Using activity types:**
Some events have activity types that give you more control over when your workflow should run. Use `on.<event_name>.types` to define the type of event activity that will trigger a workflow run.
Some events have activity types that give you more control over when your workflow should run. Use `on.<event_name>.types` to define the type of event activity that will trigger a workflow run.
For example, the `issue_comment` event has the `created`, `edited`, and `deleted` activity types. If your workflow triggers on the `label` event, it will run whenever a label is created, edited, or deleted. If you specify the `created` activity type for the `label` event, your workflow will run when a label is created but not when a label is edited or deleted.
For example, the `issue_comment` event has the `created`, `edited`, and `deleted` activity types. If your workflow triggers on the `label` event, it will run whenever a label is created, edited, or deleted. If you specify the `created` activity type for the `label` event, your workflow will run when a label is created but not when a label is edited or deleted.
```yaml
on:
label:
@ -137,7 +137,7 @@ on:
**Using filters:**
Some events have filters that give you more control over when your workflow should run.
For example, the `push` event has a `branches` filter that causes your workflow to run only when a push to a branch that matches the `branches` filter occurs, instead of when any push occurs.
For example, the `push` event has a `branches` filter that causes your workflow to run only when a push to a branch that matches the `branches` filter occurs, instead of when any push occurs.
```yaml
on:
push:
@ -147,7 +147,7 @@ on:
```
#### `on.<event_name>.types`
Use `on.<event_name>.types` to define the type of activity that will trigger a workflow run. Most [GitHub](GitHub.md) events are triggered by more than one type of activity. For example, the `label` is triggered when a label is `created`, `edited`, or `deleted`. The `types` keyword enables you to narrow down activity that causes the workflow to run. When only one activity type triggers a [webhook](../internet/Webhook.md) event, the `types` keyword is unnecessary.
Use `on.<event_name>.types` to define the type of activity that will trigger a workflow run. Most [GitHub](GitHub.md) events are triggered by more than one type of activity. For example, the `label` is triggered when a label is `created`, `edited`, or `deleted`. The `types` keyword enables you to narrow down activity that causes the workflow to run. When only one activity type triggers a [webhook](../internet/Webhook.md) event, the `types` keyword is unnecessary.
```yaml
on:
@ -156,7 +156,7 @@ on:
```
#### `on.schedule`
You can use `on.schedule` to define a time schedule for your workflows. You can schedule a workflow to run at specific UTC times using POSIX cron syntax. Scheduled workflows run on the latest commit on the default or base branch. The shortest interval you can run scheduled workflows is once every 5 minutes.
You can use `on.schedule` to define a time schedule for your workflows. You can schedule a workflow to run at specific UTC times using POSIX cron syntax. Scheduled workflows run on the latest commit on the default or base branch. The shortest interval you can run scheduled workflows is once every 5 minutes.
This example triggers the workflow every day at 5:30 and 17:30 UTC:
```yaml
@ -166,7 +166,7 @@ on:
- cron: '30 5,17 * * *'
```
A single workflow can be triggered by multiple `schedule` events. You can access the schedule event that triggered the workflow through the `github.event.schedule` context. This example triggers the workflow to run at 5:30 UTC every Monday-Thursday, but skips the `Not on Monday or Wednesday` step on Monday and Wednesday.
A single workflow can be triggered by multiple `schedule` events. You can access the schedule event that triggered the workflow through the `github.event.schedule` context. This example triggers the workflow to run at 5:30 UTC every Monday-Thursday, but skips the `Not on Monday or Wednesday` step on Monday and Wednesday.
```yaml
on:
schedule:
@ -185,31 +185,31 @@ jobs:
```
#### `on.workflow_dispatch`
When using the `workflow_dispatch` event, you can manually run this workflow from the UI.
When using the `workflow_dispatch` event, you can manually run this workflow from the UI.
#### `env`
A `map` of variables that are available to the steps of all jobs in the workflow. You can also set variables that are only available to the steps of a single job or to a single step. For more information, see `jobs.<job_id>.env` and `jobs.<job_id>.steps[*].env`.
A `map` of variables that are available to the steps of all jobs in the workflow. You can also set variables that are only available to the steps of a single job or to a single step. For more information, see `jobs.<job_id>.env` and `jobs.<job_id>.steps[*].env`.
Variables in the `env` map cannot be defined in terms of other variables in the map.
Variables in the `env` map cannot be defined in terms of other variables in the map.
**Example of `env`:**
**Example of `env`:**
```yaml
env:
SERVER: production
```
#### `jobs`
A workflow run is made up of one or more `jobs`, which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the `jobs.<job_id>.needs` keyword.
A workflow run is made up of one or more `jobs`, which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the `jobs.<job_id>.needs` keyword.
Each job runs in a runner environment specified by `runs-on`.
Each job runs in a runner environment specified by `runs-on`.
##### `jobs.<job_id>`
Use `jobs.<job_id>` to give your job a unique identifier. The key `job_id` is a string and its value is a map of the job's configuration data. You must replace `<job_id>` with a string that is unique to the `jobs` object. The `<job_id>` must start with a letter or `_` and contain only alphanumeric characters, `-`, or `_`.
Use `jobs.<job_id>` to give your job a unique identifier. The key `job_id` is a string and its value is a map of the job's configuration data. You must replace `<job_id>` with a string that is unique to the `jobs` object. The `<job_id>` must start with a letter or `_` and contain only alphanumeric characters, `-`, or `_`.
Use `jobs.<job_id>.name` to set a name for the job, which is displayed in the [GitHub](GitHub.md) UI.
Use `jobs.<job_id>.name` to set a name for the job, which is displayed in the [GitHub](GitHub.md) UI.
**Example: Creating jobs:**
In this example, two jobs have been created, and their `job_id` values are `my_first_job` and `my_second_job`.
In this example, two jobs have been created, and their `job_id` values are `my_first_job` and `my_second_job`.
```yaml
jobs:
@ -220,9 +220,9 @@ jobs:
```
##### `jobs.<job_id>.container`
Use `jobs.<job_id>.container` to create a container to run any steps in a job that don't already specify a container. If you have steps that use both script and container actions, the container actions will run as sibling containers on the same network with the same volume mounts.
Use `jobs.<job_id>.container` to create a container to run any steps in a job that don't already specify a container. If you have steps that use both script and container actions, the container actions will run as sibling containers on the same network with the same volume mounts.
If you do not set a `container`, all steps will run directly on the host specified by `runs-on` unless a step refers to an action configured to run in a container.
If you do not set a `container`, all steps will run directly on the host specified by `runs-on` unless a step refers to an action configured to run in a container.
**Example: Running a job within a container:**
```yaml
@ -247,7 +247,7 @@ jobs:
run: (ls /.dockerenv && echo Found dockerenv) || (echo No dockerenv)
```
When you only specify a container image, you can omit the `image` keyword.
When you only specify a container image, you can omit the `image` keyword.
```yaml
jobs:
container-test-job:
@ -256,7 +256,7 @@ jobs:
```
##### `jobs.<job_id>.needs`
Use `jobs.<job_id>.needs` to identify any jobs that must complete successfully before this job will run. It can be a string or array of strings. If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a conditional expression that causes the job to continue. If a run contains a series of jobs that need each other, a failure or skip applies to all jobs in the dependency chain from the point of failure or skip onwards. If you would like a job to run even if a job it is dependent on did not succeed, use the `always()` conditional expression in `jobs.<job_id>.if`.
Use `jobs.<job_id>.needs` to identify any jobs that must complete successfully before this job will run. It can be a string or array of strings. If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a conditional expression that causes the job to continue. If a run contains a series of jobs that need each other, a failure or skip applies to all jobs in the dependency chain from the point of failure or skip onwards. If you would like a job to run even if a job it is dependent on did not succeed, use the `always()` conditional expression in `jobs.<job_id>.if`.
**Example: Requiring successful dependent jobs:**
```yaml
@ -269,11 +269,11 @@ jobs:
```
##### `jobs.<job_id>.if`
You can use the `jobs.<job_id>.if` conditional to prevent a job from running unless a condition is met. You can use any supported context and expression to create a conditional.
You can use the `jobs.<job_id>.if` conditional to prevent a job from running unless a condition is met. You can use any supported context and expression to create a conditional.
When you use expressions in an `if` conditional, you can, optionally, omit the `${{ }}` expression syntax because GitHub Actions automatically evaluates the `if` conditional as an expression. However, this exception does not apply everywhere.
When you use expressions in an `if` conditional, you can, optionally, omit the `${{ }}` expression syntax because GitHub Actions automatically evaluates the `if` conditional as an expression. However, this exception does not apply everywhere.
You must always use the `${{ }}` expression syntax or escape with `''`, `""`, or `()` when the expression starts with `!`, since `!` is reserved notation in [YAML](../files/YAML.md) format. For example:
You must always use the `${{ }}` expression syntax or escape with `''`, `""`, or `()` when the expression starts with `!`, since `!` is reserved notation in [YAML](../files/YAML.md) format. For example:
```yaml
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
```
@ -281,15 +281,15 @@ if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
For more information, see "Expressions."
##### `jobs.<job_id>.runs-on`
Use `jobs.<job_id>.runs-on` to define the type of machine to run the job on.
Use `jobs.<job_id>.runs-on` to define the type of machine to run the job on.
##### `jobs.<job_id>.env`
A `map` of variables that are available to all steps in the job. You can set variables for the entire workflow or an individual step.
A `map` of variables that are available to all steps in the job. You can set variables for the entire workflow or an individual step.
##### `jobs.<job_id>.steps`
A job contains a sequence of tasks called `steps`. Steps can run commands, run setup tasks, or run an action in your repository, a public repository, or an action published in a [Docker](../tools/Docker.md) registry. Not all steps run actions, but all actions run as a step. Each step runs in its own process in the runner environment and has access to the workspace and filesystem. Because steps run in their own process, changes to [environment variables](../linux/Environment%20Variables.md) are not preserved between steps. [GitHub](GitHub.md) provides built-in steps to set up and complete a job.
A job contains a sequence of tasks called `steps`. Steps can run commands, run setup tasks, or run an action in your repository, a public repository, or an action published in a [Docker](../tools/Docker.md) registry. Not all steps run actions, but all actions run as a step. Each step runs in its own process in the runner environment and has access to the workspace and filesystem. Because steps run in their own process, changes to [environment variables](../linux/Environment%20Variables.md) are not preserved between steps. [GitHub](GitHub.md) provides built-in steps to set up and complete a job.
**Example of `jobs.<job_id>.steps`:**
**Example of `jobs.<job_id>.steps`:**
```yaml
name: Greeting from Mona
@ -311,13 +311,13 @@ jobs:
```
- `jobs.<job_id>.steps[*].if`
You can use the `if` conditional to prevent a step from running unless a condition is met. You can use any supported context and expression to create a conditional.
You can use the `if` conditional to prevent a step from running unless a condition is met. You can use any supported context and expression to create a conditional.
- `jobs.<job_id>.steps[*].name`
A name for your step to display on [GitHub](GitHub.md).
- `jobs.<job_id>.steps[*].uses`
Selects an action to run as part of a step in your job. An action is a reusable unit of code. You can use an action defined in the same repository as the workflow, a public repository, or in a published [Docker](../tools/Docker.md) container image.
Selects an action to run as part of a step in your job. An action is a reusable unit of code. You can use an action defined in the same repository as the workflow, a public repository, or in a published [Docker](../tools/Docker.md) container image.
Some actions require inputs that you must set using the `with` keyword. Review the action's README file to determine the inputs required.
Some actions require inputs that you must set using the `with` keyword. Review the action's README file to determine the inputs required.
**Example: Using versioned actions**
```yaml
@ -332,9 +332,9 @@ steps:
- uses: actions/checkout@main
```
- `jobs.<job_id>.steps[*].run`
Runs command-line programs using the operating system's [shell](../applications/cli/Shell.md). If you do not provide a `name`, the step name will default to the text specified in the `run` command. Commands run using non-login shells by default.
Runs command-line programs using the operating system's [shell](../applications/cli/Shell.md). If you do not provide a `name`, the step name will default to the text specified in the `run` command. Commands run using non-login shells by default.
Each `run` keyword represents a new process and [shell](../applications/cli/Shell.md) in the runner environment. When you provide multi-line commands, each line runs in the same [shell](../applications/cli/Shell.md). For example:
Each `run` keyword represents a new process and [shell](../applications/cli/Shell.md) in the runner environment. When you provide multi-line commands, each line runs in the same [shell](../applications/cli/Shell.md). For example:
A single-line command:
```yaml
@ -350,7 +350,7 @@ A multi-line command:
npm run build
```
- `jobs.<job_id>.steps[*].working-directory`
Using the `working-directory` keyword, you can specify the working directory of where to run the command.
Using the `working-directory` keyword, you can specify the working directory of where to run the command.
```yaml
- name: Clean temp directory
@ -358,13 +358,13 @@ Using the `working-directory` keyword, you can specify the working directory o
working-directory: ./temp
```
- `jobs.<job_id>.steps[*].with`
A `map` of the input parameters defined by the action. Each input parameter is a key/value pair. Input parameters are set as [environment variables](../linux/Environment%20Variables.md). The variable is prefixed with `INPUT_` and converted to upper case.
A `map` of the input parameters defined by the action. Each input parameter is a key/value pair. Input parameters are set as [environment variables](../linux/Environment%20Variables.md). The variable is prefixed with `INPUT_` and converted to upper case.
Input parameters defined for a [Docker](../tools/Docker.md) container must use `args`. For more information, see "`jobs.<job_id>.steps[*].with.args`."
Input parameters defined for a [Docker](../tools/Docker.md) container must use `args`. For more information, see "`jobs.<job_id>.steps[*].with.args`."
**Example of `jobs.<job_id>.steps[*].with`
**Example of `jobs.<job_id>.steps[*].with`
Defines the three input parameters (`first_name`, `middle_name`, and `last_name`) defined by the `hello_world` action. These input variables will be accessible to the `hello-world` action as `INPUT_FIRST_NAME`, `INPUT_MIDDLE_NAME`, and `INPUT_LAST_NAME` [environment variables](../linux/Environment%20Variables.md).
Defines the three input parameters (`first_name`, `middle_name`, and `last_name`) defined by the `hello_world` action. These input variables will be accessible to the `hello-world` action as `INPUT_FIRST_NAME`, `INPUT_MIDDLE_NAME`, and `INPUT_LAST_NAME` [environment variables](../linux/Environment%20Variables.md).
```yaml
jobs:
my_first_job:
@ -377,15 +377,15 @@ jobs:
last_name: Octocat
```
- `jobs.<job_id>.steps[*].with.args`
A `string` that defines the inputs for a [Docker](../tools/Docker.md) container. [GitHub](GitHub.md) passes the `args` to the container's `ENTRYPOINT` when the container starts up. An `array of strings` is not supported by this parameter. A single argument that includes spaces should be surrounded by double quotes `""`.
A `string` that defines the inputs for a [Docker](../tools/Docker.md) container. [GitHub](GitHub.md) passes the `args` to the container's `ENTRYPOINT` when the container starts up. An `array of strings` is not supported by this parameter. A single argument that includes spaces should be surrounded by double quotes `""`.
- `jobs.<job_id>.steps[*].env`
Sets variables for steps to use in the runner environment. You can also set variables for the entire workflow or a job. For more information, see `env` and `jobs.<job_id>.env`.
Sets variables for steps to use in the runner environment. You can also set variables for the entire workflow or a job. For more information, see `env` and `jobs.<job_id>.env`.
When more than one environment variable is defined with the same name, [GitHub](GitHub.md) uses the most specific variable. For example, an environment variable defined in a step will override job and workflow [environment variables](../linux/Environment%20Variables.md) with the same name, while the step executes. An environment variable defined for a job will override a workflow variable with the same name, while the job executes.
Public actions may specify expected variables in the README file. If you are setting a secret or sensitive value, such as a password or token, you must set secrets using the `secrets` context.
Public actions may specify expected variables in the README file. If you are setting a secret or sensitive value, such as a password or token, you must set secrets using the `secrets` context.
**Example of `jobs.<job_id>.steps[*].env`**
**Example of `jobs.<job_id>.steps[*].env`**
```yaml
steps:
- name: My first action
@ -396,12 +396,12 @@ steps:
```
## Events
An event is a specific activity in a repository that triggers a workflow run. For example, activity can originate from [GitHub](GitHub.md) when someone creates a pull request, opens an issue, or pushes a commit to a repository. You can also trigger a workflow to run on a schedule, by posting to a REST API, or manually.
An event is a specific activity in a repository that triggers a workflow run. For example, activity can originate from [GitHub](GitHub.md) when someone creates a pull request, opens an issue, or pushes a commit to a repository. You can also trigger a workflow to run on a schedule, by posting to a REST API, or manually.
### `create`
Runs your workflow when someone creates a [Git](Git.md) reference ([Git](Git.md) branch or tag) in the workflow's repository.
For example, you can run a workflow when the `create` event occurs.
For example, you can run a workflow when the `create` event occurs.
```yaml
on:
create
@ -410,7 +410,7 @@ on:
### `delete`
Runs your workflow when someone deletes a [Git](Git.md) reference ([Git](Git.md) branch or tag) in the workflow's repository.
For example, you can run a workflow when the `delete` event occurs.
For example, you can run a workflow when the `delete` event occurs.
```yaml
on:
delete
@ -420,21 +420,21 @@ on:
Runs your workflow when a discussion in the workflow's repository is created or modified.
Activity Types:
- `created`
- `edited`
- `deleted`
- `transferred`
- `pinned`
- `unpinned`
- `labeled`
- `unlabeled`
- `locked`
- `unlocked`
- `category_changed`
- `answered`
- `unanswered`
- `created`
- `edited`
- `deleted`
- `transferred`
- `pinned`
- `unpinned`
- `labeled`
- `unlabeled`
- `locked`
- `unlocked`
- `category_changed`
- `answered`
- `unanswered`
For example, you can run a workflow when a discussion has been `created`, `edited`, or `answered`.
For example, you can run a workflow when a discussion has been `created`, `edited`, or `answered`.
```yaml
on:
discussion:
@ -445,11 +445,11 @@ on:
Runs your workflow when a comment on a discussion in the workflow's repository is created or modified.
Activity Types:
- `created`
- `edited`
- `deleted`
- `created`
- `edited`
- `deleted`
For example, you can run a workflow when a discussion comment has been `created` or `deleted`.
For example, you can run a workflow when a discussion comment has been `created` or `deleted`.
```yaml
on:
discussion_comment:
@ -459,7 +459,7 @@ on:
### `fork`
Runs your workflow when someone forks a repository.
For example, you can run a workflow when the `fork` event occurs.
For example, you can run a workflow when the `fork` event occurs.
```yaml
on:
fork
@ -469,11 +469,11 @@ on:
Runs your workflow when an issue or pull request comment is created, edited, or deleted.
Activity Types:
- `created`
- `edited`
- `deleted`
- `created`
- `edited`
- `deleted`
For example, you can run a workflow when an issue or pull request comment has been `created` or `deleted`.
For example, you can run a workflow when an issue or pull request comment has been `created` or `deleted`.
```yaml
on:
issue_comment:
@ -484,24 +484,24 @@ on:
Runs your workflow when an issue in the workflow's repository is created or modified.
Activity Types:
- `opened`
- `edited`
- `deleted`
- `transferred`
- `pinned`
- `unpinned`
- `closed`
- `reopened`
- `assigned`
- `unassigned`
- `labeled`
- `unlabeled`
- `locked`
- `unlocked`
- `milestoned`
- `demilestoned`
- `opened`
- `edited`
- `deleted`
- `transferred`
- `pinned`
- `unpinned`
- `closed`
- `reopened`
- `assigned`
- `unassigned`
- `labeled`
- `unlabeled`
- `locked`
- `unlocked`
- `milestoned`
- `demilestoned`
For example, you can run a workflow when an issue has been `opened`, `edited`, or `milestoned`.
For example, you can run a workflow when an issue has been `opened`, `edited`, or `milestoned`.
```yaml
on:
issues:
@ -512,13 +512,13 @@ on:
Runs your workflow when a milestone in the workflow's repository is created or modified.
Activity Types:
- `created`
- `closed`
- `opened`
- `edited`
- `deleted`
- `created`
- `closed`
- `opened`
- `edited`
- `deleted`
For example, you can run a workflow when a milestone has been `opened` or `deleted`.
For example, you can run a workflow when a milestone has been `opened` or `deleted`.
```yaml
on:
milestone:
@ -529,25 +529,25 @@ on:
Runs your workflow when activity on a pull request in the workflow's repository occurs. For example, if no activity types are specified, the workflow runs when a pull request is opened or reopened or when the head branch of the pull request is updated.
Activity Types:
- `assigned`
- `unassigned`
- `labeled`
- `unlabeled`
- `opened`
- `edited`
- `closed`
- `reopened`
- `synchronize`
- `converted_to_draft`
- `ready_for_review`
- `locked`
- `unlocked`
- `milestoned`
- `demilestoned`
- `review_requested`
- `review_request_removed`
- `auto_merge_enabled`
- `auto_merge_disabled`
- `assigned`
- `unassigned`
- `labeled`
- `unlabeled`
- `opened`
- `edited`
- `closed`
- `reopened`
- `synchronize`
- `converted_to_draft`
- `ready_for_review`
- `locked`
- `unlocked`
- `milestoned`
- `demilestoned`
- `review_requested`
- `review_request_removed`
- `auto_merge_enabled`
- `auto_merge_disabled`
For example, you can run a workflow when a pull request has been opened or reopened.
```yaml
@ -559,11 +559,11 @@ on:
### `push`
Runs your workflow when you push a commit or tag, or when you create a repository from a template.
You can use the `branches` or `branches-ignore` filter to configure your workflow to only run when specific branches are pushed.
You can use the `branches` or `branches-ignore` filter to configure your workflow to only run when specific branches are pushed.
You can use the `tags` or `tags-ignore` filter to configure your workflow to only run when specific tags are pushed.
You can use the `tags` or `tags-ignore` filter to configure your workflow to only run when specific tags are pushed.
If you use both the `branches` filter and the `paths` filter, the workflow will only run when both filters are satisfied. For example, the following workflow will only run when a push that includes a change to a JavaScript (`.js`) file is made to a branch whose name starts with `releases/`:
If you use both the `branches` filter and the `paths` filter, the workflow will only run when both filters are satisfied. For example, the following workflow will only run when a push that includes a change to a JavaScript (`.js`) file is made to a branch whose name starts with `releases/`:
```yaml
on:
push:
@ -573,7 +573,7 @@ on:
- '**.js'
```
For example, you can run a workflow when the `push` event occurs.
For example, you can run a workflow when the `push` event occurs.
```yaml
on:
push
@ -583,15 +583,15 @@ on:
Runs your workflow when release activity in your repository occurs.
Activity Types:
- `published`
- `unpublished`
- `created`
- `edited`
- `deleted`
- `prereleased`
- `released`
- `published`
- `unpublished`
- `created`
- `edited`
- `deleted`
- `prereleased`
- `released`
For example, you can run a workflow when a release has been `published`.
For example, you can run a workflow when a release has been `published`.
```yaml
on:
release:
@ -599,9 +599,9 @@ on:
```
### `schedule`
The `schedule` event allows you to trigger a workflow at a scheduled time.
The `schedule` event allows you to trigger a workflow at a scheduled time.
You can schedule a workflow to run at specific UTC times using POSIX cron syntax. Scheduled workflows run on the latest commit on the default or base branch. The shortest interval you can run scheduled workflows is once every 5 minutes. A single workflow can be triggered by multiple `schedule` events. You can access the schedule event that triggered the workflow through the `github.event.schedule` context.
You can schedule a workflow to run at specific UTC times using POSIX cron syntax. Scheduled workflows run on the latest commit on the default or base branch. The shortest interval you can run scheduled workflows is once every 5 minutes. A single workflow can be triggered by multiple `schedule` events. You can access the schedule event that triggered the workflow through the `github.event.schedule` context.
This example triggers the workflow every day at 5:30 and 17:30 UTC:
```yaml
@ -612,18 +612,18 @@ on:
```
### `workflow_dispatch`
To enable a workflow to be triggered manually, you need to configure the `workflow_dispatch` event. You can manually trigger a workflow run using the [GitHub](GitHub.md) API, [GitHub](GitHub.md) CLI, or [GitHub](GitHub.md) browser interface.
To enable a workflow to be triggered manually, you need to configure the `workflow_dispatch` event. You can manually trigger a workflow run using the [GitHub](GitHub.md) API, [GitHub](GitHub.md) CLI, or [GitHub](GitHub.md) browser interface.
```yaml
on: workflow_dispatch
```
## Jobs
A job is a set of _steps_ in a workflow that is executed on the same runner. Each step is either a [shell](../applications/cli/Shell.md) script that will be executed, or an _action_ that will be run. Steps are executed in order and are dependent on each other. Since each step is executed on the same runner, you can share data from one step to another. For example, you can have a step that builds your application followed by a step that tests the application that was built.
A job is a set of _steps_ in a workflow that is executed on the same runner. Each step is either a [shell](../applications/cli/Shell.md) script that will be executed, or an _action_ that will be run. Steps are executed in order and are dependent on each other. Since each step is executed on the same runner, you can share data from one step to another. For example, you can have a step that builds your application followed by a step that tests the application that was built.
You can configure a job's dependencies with other jobs; by default, jobs have no dependencies and run in parallel with each other. When a job takes a dependency on another job, it will wait for the dependent job to complete before it can run. For example, you may have multiple build jobs for different architectures that have no dependencies, and a packaging job that is dependent on those jobs. The build jobs will run in parallel, and when they have all completed successfully, the packaging job will run.
## Actions
An _action_ is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. Use an action to help reduce the amount of repetitive code that you write in your workflow files. An action can pull your [git](Git.md) repository from [GitHub](GitHub.md), set up the correct toolchain for your build environment, or set up the authentication to your cloud provider.
An _action_ is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. Use an action to help reduce the amount of repetitive code that you write in your workflow files. An action can pull your [git](Git.md) repository from [GitHub](GitHub.md), set up the correct toolchain for your build environment, or set up the authentication to your cloud provider.
You can write your own actions, or you can find actions to use in your workflows in the GitHub Marketplace.

View file

@ -79,7 +79,7 @@ Conditionals like `if` and `match` can be used, while `match` can do more powerf
let age = 20;
if age > 18 {
println!("Adult");
} else if age == 18 {
} else if age == 18 {
println!("Exactly 18");
} else {
println!("Minor");
@ -156,7 +156,7 @@ struct Person {
impl Person {
fn new(first_name: &str) -> Self {
Self {
Self {
first_name: first_name.to_string(),
age: 0
}

View file

@ -10,7 +10,7 @@ A database most often contains one or more tables. Each table is identified by a
Most of the actions you need to perform on a database are done with SQL statements.
Example:
```sql
SELECT * FROM Customers;
SELECT * FROM Customers;
```
### Comments
@ -31,12 +31,12 @@ SELECT * FROM Customers;
```
## SELECT
The `SELECT` statement is used to select data from a database.
The `SELECT` statement is used to select data from a database.
Select:
```sql
SELECT column1, column2, ...
FROM table_name;
SELECT column1, column2, ...
FROM table_name;
```
Select all:
@ -45,7 +45,7 @@ SELECT * FROM table
```
### SELECT DISTINC
The `SELECT DISTINCT` statement is used to return only distinct (different) values.
The `SELECT DISTINCT` statement is used to return only distinct (different) values.
```sql
SELECT DISTINCT Country FROM Customers;
@ -53,7 +53,7 @@ SELECT COUNT(DISTINCT Country) FROM Customers;
```
## WHERE
The `WHERE` clause is used to filter records.
The `WHERE` clause is used to filter records.
```sql
SELECT column1, column2, ...
@ -71,7 +71,7 @@ SELECT * FROM Customers
WHERE CustomerID=1;
```
The following operators can be used in the `WHERE` clause:
The following operators can be used in the `WHERE` clause:
| Operator | Description |
| -------- | ------------------------------------------------------------------------------- |
@ -80,17 +80,17 @@ The following operators can be used in the `WHERE` clause:
| < | Less than |
| >= | Greater than or equal |
| <= | Less than or equal |
| <> | Not equal. **Note:** In some versions of SQL this operator may be written as != |
| <> | Not equal. **Note:** In some versions of SQL this operator may be written as != |
| BETWEEN | Between a certain range |
| LIKE | Search for a pattern |
| IN | To specify multiple possible values for a column |
### LIKE
The `LIKE` operator is used in a `WHERE` clause to search for a specified pattern in a column.
The `LIKE` operator is used in a `WHERE` clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the `LIKE` operator:
-  The percent sign `%` represents zero, one, or multiple characters
-  The underscore sign `_` represents one, single character
There are two wildcards often used in conjunction with the `LIKE` operator:
- The percent sign `%` represents zero, one, or multiple characters
- The underscore sign `_` represents one, single character
```sql
SELECT column1, column2, ...
@ -99,72 +99,72 @@ WHERE columnN LIKE pattern;
```
#### The _ Wildcard
The `_` wildcard represents a single character.
It can be any character or number, but each `_` represents one, and only one, character.
The `_` wildcard represents a single character.
It can be any character or number, but each `_` represents one, and only one, character.
```sql
SELECT * FROM Customers
WHERE city LIKE 'L_nd__';
SELECT * FROM Customers
WHERE city LIKE 'L_nd__';
```
#### The % Wildcard
The `%` wildcard represents any number of characters, even zero characters.
The `%` wildcard represents any number of characters, even zero characters.
```sql
SELECT * FROM Customers
WHERE city LIKE '%L%';
SELECT * FROM Customers
WHERE city LIKE '%L%';
```
#### Starts With
```sql
SELECT * FROM Customers
WHERE CustomerName LIKE 'La%';
SELECT * FROM Customers
WHERE CustomerName LIKE 'La%';
```
#### Ends With
```sql
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
```
#### Contains
```sql
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';
```
### IN
The `IN` operator allows you to specify multiple values in a `WHERE` clause.
The `IN` operator allows you to specify multiple values in a `WHERE` clause.
The `IN` operator is a shorthand for multiple `OR` conditions.
The `IN` operator is a shorthand for multiple `OR` conditions.
```sql
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
```
Subquery:
```sql
SELECT * FROM Customers
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);
SELECT * FROM Customers
WHERE CustomerID NOT IN (SELECT CustomerID FROM Orders);
```
### BETWEEN
The `BETWEEN` operator selects values within a given range. The values can be numbers, text, or dates.
The `BETWEEN` operator selects values within a given range. The values can be numbers, text, or dates.
The `BETWEEN` operator is inclusive: begin and end values are included.
The `BETWEEN` operator is inclusive: begin and end values are included.
```sql
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
SELECT * FROM Orders
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';
SELECT * FROM Orders
WHERE OrderDate BETWEEN '1996-07-01' AND '1996-07-31';
```
### AND
The `WHERE` clause can contain one or many `AND` operators.
The `WHERE` clause can contain one or many `AND` operators.
```sql
SELECT *
@ -173,7 +173,7 @@ WHERE Country = 'Spain' AND CustomerName LIKE 'G%';
```
### OR
The `WHERE` clause can contain one or more `OR` operators.
The `WHERE` clause can contain one or more `OR` operators.
```sql
SELECT *
@ -188,20 +188,20 @@ WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%');
```
### NOT
The `NOT` operator is used in combination with other operators to give the opposite result, also called the negative result.
The `NOT` operator is used in combination with other operators to give the opposite result, also called the negative result.
```sql
SELECT * FROM Customers
WHERE NOT Country = 'Spain';
SELECT * FROM Customers
WHERE NOT Country = 'Spain';
SELECT * FROM Customers
WHERE City NOT IN ('Paris', 'London');
SELECT * FROM Customers
WHERE City NOT IN ('Paris', 'London');
```
## ORDER BY
The `ORDER BY` keyword is used to sort the result-set in ascending or descending order.
The `ORDER BY` keyword is used to sort the result-set in ascending or descending order.
The `ORDER BY` keyword sorts the records in ascending order by default. To sort the records in descending order, use the `DESC` keyword.
The `ORDER BY` keyword sorts the records in ascending order by default. To sort the records in descending order, use the `DESC` keyword.
```sql
SELECT column1, column2, ...
@ -210,7 +210,7 @@ ORDER BY column1, column2, ... ASC|DESC;
```
## INSERT INTO
The `INSERT INTO` statement is used to insert new records in a table.
The `INSERT INTO` statement is used to insert new records in a table.
Example:
```sql
@ -228,7 +228,7 @@ VALUES
```
## UPDATE
The `UPDATE` statement is used to modify the existing records in a table.
The `UPDATE` statement is used to modify the existing records in a table.
```sql
UPDATE table_name
@ -237,7 +237,7 @@ WHERE condition;
```
## DELETE
The `DELETE` statement is used to delete existing records in a table.
The `DELETE` statement is used to delete existing records in a table.
Example:
```sql
@ -251,11 +251,11 @@ DELETE FROM table_name;
Delete Table:
```sql
DROP TABLE table_name;
DROP TABLE table_name;
```
## LIMIT
The `LIMIT` clause is used to specify the number of records to return.
The `LIMIT` clause is used to specify the number of records to return.
```sql
SELECT * FROM Customers
@ -266,7 +266,7 @@ LIMIT 3;
SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable.
An alias only exists for the duration of that query.
An alias is created with the `AS` keyword.
An alias is created with the `AS` keyword.
```sql
SELECT column_name AS alias_name
@ -274,34 +274,34 @@ FROM table_name;
```
## JOIN
A `JOIN` clause is used to combine rows from two or more tables, based on a related column between them.
A `JOIN` clause is used to combine rows from two or more tables, based on a related column between them.
### INNER JOIN
The `INNER JOIN` keyword selects records that have matching values in both tables.
The `INNER JOIN` keyword selects records that have matching values in both tables.
```sql
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
```
# Database
## Create Database
The `CREATE DATABASE` statement is used to create a new SQL database.
The `CREATE DATABASE` statement is used to create a new SQL database.
```sql
CREATE DATABASE databasename;
```
## Delete Database
The `DROP DATABASE` statement is used to drop an existing SQL database.
The `DROP DATABASE` statement is used to drop an existing SQL database.
```sql
DROP DATABASE databasename;
```
## Create Table
The `CREATE TABLE` statement is used to create a new table in a database.
The `CREATE TABLE` statement is used to create a new table in a database.
```sql
CREATE TABLE table_name (
@ -321,15 +321,15 @@ CREATE TABLE Persons (
```
## Delete Table
The `DROP TABLE` statement is used to drop an existing table in a database.
The `DROP TABLE` statement is used to drop an existing table in a database.
```sql
DROP TABLE table_name;
```
## Change Table
The `ALTER TABLE` statement is used to add, delete, or modify columns in an existing table.
The `ALTER TABLE` statement is also used to add and drop various constraints on an existing table.
The `ALTER TABLE` statement is used to add, delete, or modify columns in an existing table.
The `ALTER TABLE` statement is also used to add and drop various constraints on an existing table.
Add Column:
```sql
@ -339,8 +339,8 @@ ADD Email varchar(255);
Drop Column:
```sql
ALTER TABLE Customers
DROP COLUMN Email;
ALTER TABLE Customers
DROP COLUMN Email;
```
Rename Column:
@ -356,7 +356,7 @@ ALTER COLUMN DateOfBirth year;
```
## Constraints
Constraints can be specified when the table is created with the `CREATE TABLE` statement, or after the table is created with the `ALTER TABLE` statement.
Constraints can be specified when the table is created with the `CREATE TABLE` statement, or after the table is created with the `ALTER TABLE` statement.
```sql
CREATE TABLE table_name (
@ -371,30 +371,30 @@ The following constraints are commonly used in SQL:
### NOT NULL
By default, a column can hold NULL values.
The `NOT NULL` constraint enforces a column to NOT accept NULL values.
The `NOT NULL` constraint enforces a column to NOT accept NULL values.
This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.
```sql
CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255) NOT NULL,
    Age int
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int
);
```
### UNIQUE
The `UNIQUE` constraint ensures that all values in a column are different.
The `UNIQUE` constraint ensures that all values in a column are different.
Both the `UNIQUE` and `PRIMARY KEY` constraints provide a guarantee for uniqueness for a column or set of columns.
Both the `UNIQUE` and `PRIMARY KEY` constraints provide a guarantee for uniqueness for a column or set of columns.
A `PRIMARY KEY` constraint automatically has a `UNIQUE` constraint.
A `PRIMARY KEY` constraint automatically has a `UNIQUE` constraint.
However, you can have many `UNIQUE` constraints per table, but only one `PRIMARY KEY` constraint per table.
However, you can have many `UNIQUE` constraints per table, but only one `PRIMARY KEY` constraint per table.
### PRIMARY KEY
The `PRIMARY KEY` constraint uniquely identifies each record in a table.
The `PRIMARY KEY` constraint uniquely identifies each record in a table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
@ -411,9 +411,9 @@ CREATE TABLE Persons (
```
### FOREIGN KEY
The `FOREIGN KEY` constraint is used to prevent actions that would destroy links between tables.
The `FOREIGN KEY` constraint is used to prevent actions that would destroy links between tables.
A `FOREIGN KEY` is a field (or collection of fields) in one table, that refers to the `PRIMARY KEY` in another table.
A `FOREIGN KEY` is a field (or collection of fields) in one table, that refers to the `PRIMARY KEY` in another table.
The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.
@ -428,32 +428,32 @@ CREATE TABLE Orders (
```
### CHECK
The `CHECK` constraint is used to limit the value range that can be placed in a column.
The `CHECK` constraint is used to limit the value range that can be placed in a column.
If you define a `CHECK` constraint on a column it will allow only certain values for this column.
If you define a `CHECK` constraint on a column it will allow only certain values for this column.
If you define a `CHECK` constraint on a table it can limit the values in certain columns based on values in other columns in the row.
If you define a `CHECK` constraint on a table it can limit the values in certain columns based on values in other columns in the row.
```sql
CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    CHECK (Age>=18)
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CHECK (Age>=18)
);
```
### DEFAULT
The `DEFAULT` constraint is used to set a default value for a column.
The `DEFAULT` constraint is used to set a default value for a column.
The default value will be added to all new records, if no other value is specified.
```sql
CREATE TABLE Orders (
    ID int NOT NULL,
    OrderNumber int NOT NULL,
    OrderDate date DEFAULT GETDATE()
CREATE TABLE Orders (
ID int NOT NULL,
OrderNumber int NOT NULL,
OrderDate date DEFAULT GETDATE()
);
```
@ -463,17 +463,17 @@ Auto-increment allows a unique number to be generated automatically when a new r
Often this is the primary key field that we would like to be created automatically every time a new record is inserted.
```sql
CREATE TABLE Persons (
    Personid int NOT NULL AUTO_INCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (Personid)
CREATE TABLE Persons (
Personid int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (Personid)
);
```
## Create Index
The `CREATE INDEX` statement is used to create indexes in tables.
The `CREATE INDEX` statement is used to create indexes in tables.
Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot see the indexes, they are just used to speed up searches/queries.
@ -483,20 +483,20 @@ ON table_name (column1, column2, ...);
```
## Dates
**MySQL** comes with the following data types for storing a date or a date/time value in the database:
- `DATE` - format YYYY-MM-DD
- `DATETIME` - format: YYYY-MM-DD HH:MI:SS
- `TIMESTAMP` - format: YYYY-MM-DD HH:MI:SS
- `YEAR` - format YYYY or YY
**MySQL** comes with the following data types for storing a date or a date/time value in the database:
- `DATE` - format YYYY-MM-DD
- `DATETIME` - format: YYYY-MM-DD HH:MI:SS
- `TIMESTAMP` - format: YYYY-MM-DD HH:MI:SS
- `YEAR` - format YYYY or YY
## Data Types
### String
| Data type | Description |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CHAR(size) | A FIXED length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the column length in characters - can be from 0 to 255. Default is 1 |
| VARCHAR(size) | A VARIABLE length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the maximum string length in characters - can be from 0 to 65535 |
| BINARY(size) | Equal to CHAR(), but stores binary byte strings. The _size_ parameter specifies the column length in bytes. Default is 1 |
| VARBINARY(size) | Equal to VARCHAR(), but stores binary byte strings. The _size_ parameter specifies the maximum column length in bytes. |
| CHAR(size) | A FIXED length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the column length in characters - can be from 0 to 255. Default is 1 |
| VARCHAR(size) | A VARIABLE length string (can contain letters, numbers, and special characters). The _size_ parameter specifies the maximum string length in characters - can be from 0 to 65535 |
| BINARY(size) | Equal to CHAR(), but stores binary byte strings. The _size_ parameter specifies the column length in bytes. Default is 1 |
| VARBINARY(size) | Equal to VARCHAR(), but stores binary byte strings. The _size_ parameter specifies the maximum column length in bytes. |
| TINYBLOB | For BLOBs (Binary Large Objects). Max length: 255 bytes |
| TINYTEXT | Holds a string with a maximum length of 255 characters |
| TEXT(size) | Holds a string with a maximum length of 65,535 bytes |
@ -511,21 +511,21 @@ ON table_name (column1, column2, ...);
### Numeric
| Data type | Description |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BIT(_size_) | A bit-value type. The number of bits per value is specified in _size_. The _size_ parameter can hold a value from 1 to 64. The default value for _size_ is 1. |
| TINYINT(_size_) | A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The _size_ parameter specifies the maximum display width (which is 255) |
| BIT(_size_) | A bit-value type. The number of bits per value is specified in _size_. The _size_ parameter can hold a value from 1 to 64. The default value for _size_ is 1. |
| TINYINT(_size_) | A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The _size_ parameter specifies the maximum display width (which is 255) |
| BOOL | Zero is considered as false, nonzero values are considered as true. |
| BOOLEAN | Equal to BOOL |
| SMALLINT(_size_) | A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The _size_ parameter specifies the maximum display width (which is 255) |
| MEDIUMINT(_size_) | A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. The _size_ parameter specifies the maximum display width (which is 255) |
| INT(_size_) | A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The _size_ parameter specifies the maximum display width (which is 255) |
| SMALLINT(_size_) | A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The _size_ parameter specifies the maximum display width (which is 255) |
| MEDIUMINT(_size_) | A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. The _size_ parameter specifies the maximum display width (which is 255) |
| INT(_size_) | A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The _size_ parameter specifies the maximum display width (which is 255) |
| INTEGER(_size_) | Equal to INT(size) |
| BIGINT(_size_) | A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. The _size_ parameter specifies the maximum display width (which is 255) |
| FLOAT(_size_, _d_) | A floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions |
| FLOAT(_p_) | A floating point number. MySQL uses the _p_ value to determine whether to use FLOAT or DOUBLE for the resulting data type. If _p_ is from 0 to 24, the data type becomes FLOAT(). If _p_ is from 25 to 53, the data type becomes DOUBLE() |
| DOUBLE(_size_, _d_) | A normal-size floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter |
| DOUBLE PRECISION(_size_, _d_) | |
| DECIMAL(_size_, _d_) | An exact fixed-point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. The maximum number for _size_ is 65. The maximum number for _d_ is 30. The default value for _size_ is 10. The default value for _d_ is 0. |
| DEC(_size_, _d_) | Equal to DECIMAL(size,d) |
| BIGINT(_size_) | A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. The _size_ parameter specifies the maximum display width (which is 255) |
| FLOAT(_size_, _d_) | A floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions |
| FLOAT(_p_) | A floating point number. MySQL uses the _p_ value to determine whether to use FLOAT or DOUBLE for the resulting data type. If _p_ is from 0 to 24, the data type becomes FLOAT(). If _p_ is from 25 to 53, the data type becomes DOUBLE() |
| DOUBLE(_size_, _d_) | A normal-size floating point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter |
| DOUBLE PRECISION(_size_, _d_) | |
| DECIMAL(_size_, _d_) | An exact fixed-point number. The total number of digits is specified in _size_. The number of digits after the decimal point is specified in the _d_ parameter. The maximum number for _size_ is 65. The maximum number for _d_ is 30. The default value for _size_ is 10. The default value for _d_ is 0. |
| DEC(_size_, _d_) | Equal to DECIMAL(size,d) |
### Date & Time
| Data type | Description |
@ -570,7 +570,7 @@ SELECT UPPER("SQL");
The `TRIM()` function removes leading and trailing spaces from a string. `LTRIM()` & `RTRIM()` remove leading and trailing spaces from the left or right respectively.
```sql
SELECT TRIM('    SQL    ') AS TrimmedString;
SELECT TRIM(' SQL ') AS TrimmedString;
```
### SUBSTRING()
@ -602,7 +602,7 @@ The `REVERSE()` function reverses a string and returns the result.
The `REPLACE()` function replaces all occurrences of a substring within a string, with a new substring.
```sql
REPLACE(string, from_string, new_string)
REPLACE(string, from_string, new_string)
```
### REPEAT()
@ -614,50 +614,50 @@ REPEAT(string, number)
## Numeric Functions
### MIN() & MAX()
The `MIN()` function returns the smallest value of the selected column.
The `MIN()` function returns the smallest value of the selected column.
The `MAX()` function returns the largest value of the selected column.
The `MAX()` function returns the largest value of the selected column.
```sql
SELECT MIN(Price)
FROM Products;
SELECT MIN(Price)
FROM Products;
SELECT MAX(Price)
FROM Products;
SELECT MAX(Price)
FROM Products;
```
### COUNT()
The `COUNT()` function returns the number of rows that matches a specified criterion.
The `COUNT()` function returns the number of rows that matches a specified criterion.
```sql
SELECT COUNT(*)
FROM Products;
SELECT COUNT(*)
FROM Products;
```
### SUM()
The `SUM()` function returns the total sum of a numeric column.
The `SUM()` function returns the total sum of a numeric column.
Example:
```sql
SELECT SUM(Quantity) AS total
FROM OrderDetails;
SELECT SUM(Quantity) AS total
FROM OrderDetails;
```
Expressions:
```sql
SELECT SUM(Quantity * 10)
FROM OrderDetails;
SELECT SUM(Quantity * 10)
FROM OrderDetails;
```
### AVG()
The `AVG()` function returns the average value of a numeric column.
The `AVG()` function returns the average value of a numeric column.
```sql
SELECT AVG(Price)
FROM Products;
SELECT AVG(Price)
FROM Products;
SELECT * FROM Products
WHERE price > (SELECT AVG(price) FROM Products);
SELECT * FROM Products
WHERE price > (SELECT AVG(price) FROM Products);
```
## Date Functions