SELECT * FROM table_name
and Format of SQL Commands
SELECT * FROM table_name
is the most basic command of SQL. It reads data from database.
mysql> SELECT * FROM sample21;
+------+-----------+------------+---------------------------+
| no | name | birthday | address |
+------+-----------+------------+---------------------------+
| 1 | 박준용 | 1976-10-18 | 대구광역시 수성구 |
| 2 | 김재진 | NULL | 대구광역시 동구 |
| 3 | 홍길동 | NULL | 서울특별시 마포구 |
+------+-----------+------------+---------------------------+
3 rows in set (0.00 sec)
Let’s look closely at the command and its format.
SELECT
: A kind of command.*
: Specify columns. ‘*’ means all columns.sample21
: A name of a database.;
: Semi-colon. Must use at the end of the command.
SQL command consists of multiple phrases. Words such as SELECT
and FROM
divides the phrases. They are called ‘reserved words’, which means the words could not be used as a name of a database.
In SQL, uppercase and lowercase means the same. For better representation, use uppercase for reserved words, and lowercase for database.
Table
Table is an output of SELECT
command. It consists of rows and columns. Each column has its own datatype(e.g. numeric, string). One column can have only one datatype.
Numeric data is left aligned, and string and date datatype are right aligned.
NULL means nothing is stored. It is a ‘state’ not a ‘data’.
All images, except those with separate source indications, are excerpted from lecture materials.
댓글남기기