The simplest form of SELECT
retrieves everything from a table:SELECT
的最简单形式是从表中检索所有内容:
mysql> SELECT * FROM pet;
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+--------+---------+------+------------+------------+
This form of 这种形式的SELECT
uses *
, which is shorthand for “select all columns.” SELECT
使用*
,它是“选择所有列”的简写。This is useful if you want to review your entire table, for example, after you've just loaded it with your initial data set. 如果您想查看整个表,例如,在您刚刚用初始数据集加载它之后,这非常有用。For example, you may happen to think that the birth date for Bowser doesn't seem quite right. 例如,您可能会认为Bowser的出生日期似乎不太正确。Consulting your original pedigree papers, you find that the correct birth year should be 1989, not 1979.查阅你的原始家谱,你会发现正确的出生年份应该是1989年,而不是1979年。
There are at least two ways to fix this:至少有两种方法可以解决此问题:
Edit the file 编辑文件pet.txt
to correct the error, then empty the table and reload it using DELETE
and LOAD DATA
:pet.txt
以更正错误,然后使用DELETE
和LOAD DATA
清空表格并重新加载:
mysql>DELETE FROM pet;
mysql>LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
However, if you do this, you must also re-enter the record for Puffball.但是,如果您这样做,您还必须重新输入Puffball的记录。
Fix only the erroneous record with an 使用UPDATE
statement:UPDATE
语句仅修复错误记录:
mysql> UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
The UPDATE
changes only the record in question and does not require you to reload the table.UPDATE
仅更改相关记录,不需要重新加载表。
There is an exception to the principle that SELECT *
selects all columns. SELECT *
选择所有列的原则有一个例外。If a table contains invisible columns, 如果表包含不可见列,*
does not include them. *
不包含这些列。For more information, see Section 13.1.20.10, “Invisible Columns”.有关更多信息,请参阅第13.1.20.10节,“不可见列”。