SQL (Structured Query Language)
======
**SQL** is used to access and manipulate a **database**.
**MySQL** is a program that understands **SQL**.
SQL can:
- insert, update, or delete records in a database.
- create new databases, table, stored procedures, views.
- retrieve data from a database, etc.
SQL is an ANSI (American National Standards Institute) standard, but there are different versions of the SQL language.
Most SQL database programs have their own proprietary extensions in addition to the SQL standard, but all of them support the major commands.
## Concept
A **database** is a collection of data that is organized in a manner that facilitates ease of access, as well as efficient management and updating.
A database is made up of **tables** that store relevant information.
A table stores and displays data in a structured format consisting of **columns** and **rows** that are similar to those seen in Excel spreadsheets.
### Primary Key
A primary key is a field in the table that uniquely identifies the table records.
The primary key's main features:
- It must contain a **unique value** for each row.
- It cannot contain `NULL` values.
Note that,
- Tables are limited to **ONE** primary key each.
- The primary key's value must be different for each row.
## Syntax
### Logical Operators
Note that, to compare with a text value, you need to surround the text that appears in the statement with **single quotation marks (')**.
| Operators | Notes |
| ----------------- | ------------------------------------------------------------ |
| `=` | Equal |
| `!=` | Not equal |
| `>` | Greater than |
| `<` | Less than |
| `>=` | Greater than or equal |
| `<=` | Less than or equal |
| `BETWEEN a AND b` | Between an inclusive range, that is, `a <= x <= b` |
| `AND` | True if **both** expressions are True |
| `OR` | True if **either** expressions is True |
| `a IN (b, c, d)` | True if the operand is equal to one of a list of expressions |
| `NOT` | Returns True if expression is not True |
| `a LIKE pattern` | SQL **pattern** matching enables you to use `_` to match any single character and `%` to match an arbitrary number of characters (including zero characters). |
### Arithmetic Operators
| Operators | Notes |
| --------- | -------------- |
| `+` | addition |
| `-` | subtraction |
| `*` | multiplication |
| `/` | division |
### Data Types
| Type | Category | Notes |
| -------------- | ------------- | ------------------------------------------------------------ |
| `int` | Numeric | A normal-sized integer that can be signed or unsigned. |
| `float(n, d)` | Numeric | A floating-point number that cannot be unsigned. You can optionally define the display length (`n`) and the number of decimals (`d`). |
| `double(n, d)` | Numeric | A double precision floating-point number that cannot be unsigned. You can optionally define the display length (`n`) and the number of decimals (`d`). |
| `date` | Date and Time | A date in `YYYY-MM-DD` format. |
| `datetime` | Date and Time | A date and time combination in `YYYY-MM-DD HH:MM:SS` format. |
| `time` | Date and Time | A time in `HH:MM:SS` format. |
| `timestamp` | Date and Time | A timestamp, calculated from midnight, January 1, 1970. |
| `char(n)` | String | Fixed-length (`n`) character string. Size is specified in parenthesis. Max 255 bytes. |
| `varchar(n)` | String | Variable-length(`n`)character string. Max size is specified in parenthesis. |
| `blob` | String | **Binary Large Objects** and are used to store large amounts of binary data, such as images or other types of files. |
| `text` | String | Large amount of text data. |
### Multiple Queries
SQL allows to run multiple queries or commands at the same time.
Remember to end each SQL statement with a **semicolon** to indicate that the statement is complete and ready to be interpreted.
In this tutorial, we will use **semicolon** at the end of each SQL statement.
```sql
SELECT FirstName FROM customers;
SELECT City FROM customers;
```
### Case Sensitivity
SQL is case **insensitive**.
It is common practice to write all SQL commands in **upper-case**.
### Separator
A single SQL statement can be placed on one or more text lines. In addition, multiple SQL statements can be combined on a single text line.
White spaces and multiple lines are ignored in SQL. However, it is recommended to avoid unnecessary white spaces and lines.
Combined with proper spacing and indenting, breaking up the commands into logical lines will make your SQL statements much easier to read and maintain.
## Command
### Database
| Commands | Notes |
| ---------------- | ----------------------------------------- |
| `SHOW DATABASES` | list the databases managed by the server. |
### Table
#### SQL constraints
- `NOT NULL` - Indicates that a column cannot contain any NULL value.
- `UNIQUE` - Does not allow to insert a duplicate value in a column. The `UNIQUE` constraint maintains the uniqueness of a column in a table. More than one `UNIQUE` column can be used in a table.
- `AUTO_INCREMENT` - Auto-increment allows a unique number to be generated when a new record is inserted into a table. By default, the starting value for `AUTO_INCREMENT` is 1, and it will increment by 1 for each new record.
- `PRIMARY KEY` - Enforces the table to accept unique data for a specific column and this constraint create a unique index for accessing the table faster.
- `CHECK` - Determines whether the value is valid or not from a logical expression.
- `DEFAULT` - While inserting data into a table, if no value is supplied to a column, then the column gets the value set as `DEFAULT`.
#### Views
In SQL, a VIEW is a **virtual table** that is based on the result-set of an SQL statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
A view always shows up-to-date data! The database engine uses the view's SQL statement to recreate the data each time a user queries a view.
Views allow us to:
- Structure data in a way that users or classes of users find natural or intuitive.
- Restrict access to the data in such a way that a user can see and (sometimes) modify exactly what they need and no more.
- Summarize data from various tables and use it to generate reports.
| Commands | Notes |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| `SHOW TABLES` | display all of the tables in the currently selected MySQL database. |
| `CREATE TABLE Users ( UserID int NOT NULL AUTO_INCREMENT, FirstName varchar(40) NOT NULL, LastName varchar(40) NOT NULL, PRIMARY KEY(UserID) )` | Note the **parentheses** in the syntax. When inserting a new record into the Users table, it's not necessary to specify a value for the `UserID` column; a unique new value will be added automatically. |
| `DROP TABLE table`
没有合适的资源?快使用搜索试试~ 我知道了~
算法竞赛的挑战,总结实现_Python_JavaScript_下载.zip
共638个文件
py:598个
md:20个
js:16个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 58 浏览量
2023-04-30
10:21:15
上传
评论
收藏 383KB ZIP 举报
温馨提示
算法竞赛的挑战,总结实现_Python_JavaScript_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
算法竞赛的挑战,总结实现_Python_JavaScript_下载.zip (638个子文件)
243_amicable_pair 776B
.editorconfig 205B
.gitignore 37B
sudoku_solution_validator.js 1KB
simple_encryption_1_alternating_split.js 806B
deep_fetch.test.js 485B
who_likes_it.js 432B
take_a_ten_minute_walk.js 396B
delete_occurrences_of_an_element_if_it_occurs_more_than_n_times.js 386B
rectangle_into_squares.js 384B
iq_test.js 347B
test_javascript.js 282B
deep_fetch.js 268B
is_a_number_prime.js 256B
unique_in_order.js 248B
tribonacci_sequence.js 205B
double_cola.js 175B
reverse_words.js 125B
multiply.js 43B
README.md 17KB
runtime_of_builtins.md 10KB
README.md 9KB
README.md 7KB
README.md 4KB
matrix.md 3KB
README.md 2KB
latency.md 2KB
README.md 2KB
traversal.md 2KB
traversal.md 2KB
README.md 861B
complexity_analysis.md 777B
README.md 605B
subarray_sum.md 520B
README.md 485B
binary_search.md 470B
binary_tree.md 288B
substring_with_distinct_characters.md 266B
README.md 229B
robot_cleaner.py 11KB
509_mini_yelp.py 7KB
unique_paths_with_followups.py 7KB
get_most_popular_word.py 6KB
linked_list__test.py 5KB
574_build_post_office.py 5KB
437_copy_books.py 5KB
285_inorder_successor_in_bst.py 5KB
find_treasure_in_maze.py 5KB
cyclic_list.py 4KB
candy_crush.py 4KB
_helper.py 4KB
the_point_inside_polygon.py 4KB
cyclic_doubly_list.py 4KB
499_the_maze_iii.py 4KB
heap__test.py 4KB
24_lfu_cache.py 4KB
573_build_post_office_ii.py 4KB
775_palindrome_pairs.py 3KB
353_design_snake_game.py 3KB
inorder_non_threaded_binary_tree_traversal.py 3KB
227_basic_calculator_ii.py 3KB
553_bomb_enemy.py 3KB
505_the_maze_ii.py 3KB
109_triangle.py 3KB
morris_traversal.py 3KB
calculator_in_bit.py 3KB
unique_word_abbreviation_ii.py 3KB
289_game_of_life.py 3KB
534_house_robber_ii.py 3KB
368_expression_evaluation.py 3KB
377_combination_sum_iv.py 3KB
390_find_peak_element_ii.py 3KB
224_basic_calculator.py 3KB
737_sentence_similarity_ii.py 3KB
430_scramble_string.py 3KB
749_contain_virus.py 3KB
510_maximal_rectangle.py 3KB
hashtable.py 3KB
trie__test.py 3KB
417_pacific_atlantic_water_flow.py 3KB
136_palindrome_partitioning.py 3KB
sales_path.py 3KB
498_parking_lot.py 3KB
231_typeahead.py 3KB
143_sort_colors_ii.py 2KB
65_median_of_two_sorted_arrays.py 2KB
sentence_reverse.py 2KB
630_knight_shortest_path_ii.py 2KB
geohash.py 2KB
binary_tree_maximum_path_product.py 2KB
98_sort_list.py 2KB
is_valid_relation.py 2KB
480_sliding_window_median.py 2KB
binary_hash_heap.py 2KB
decrypt_message.py 2KB
freq_iterator.py 2KB
76_longest_increasing_subsequence.py 2KB
635_boggle_game.py 2KB
688_knight_probability_in_chessboard.py 2KB
360_sliding_window_median.py 2KB
共 638 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- keke-15-cdn.mobileconfig
- springmvc上传文件需要的jar
- 数据库课程设计:长途汽车信息管理数据库设计
- 高分项目,基于Unity3D开发实现的2D游戏开发专用插件,内含完整源码+资源+unitypackage
- 高分项目,基于Unity3D开发实现的手指足球Finger Soccer Game,内含完整源码+资源+unitypackage
- 中草药识别项目-5类中药材识别数据集902张(当参、金银花、槐花、枸杞、百合).zip
- 基于Scratch在线教学平台设计与实现
- 高分项目,基于Unity3D开发实现的卡通赛车赛艇游戏,内含完整源码+资源+unitypackage
- M2M开发套件程序 2024-6-12
- の2(⊙o⊙)…2343214231423432
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功