프로그래밍 정리/SQL

[SQL] MariaDB 연습2

주누다 2015. 5. 8. 00:55
반응형

abasesl' at line 1
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| st_db              |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> user st_db;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'user st_db' at line 1
MariaDB [(none)]> use st_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [st_db]> create table st_janghak;
ERROR 1113 (42000): A table must have at least 1 column
MariaDB [st_db]> create table st_janghak (ST_ID int Not Null primary key, Money int);
Query OK, 0 rows affected (0.31 sec)

MariaDB [st_db]> explain st_janghak;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| ST_ID | int(11) | NO   | PRI | NULL    |       |
| Money | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

MariaDB [st_db]> insert into st_janghak values (201401, 500000);
Query OK, 1 row affected (0.05 sec)

MariaDB [st_db]> insert into st_janghak values (201402, 1000000);
Query OK, 1 row affected (0.05 sec)

MariaDB [st_db]> insert into st_janghak values (201403, 1500000);
Query OK, 1 row affected (0.04 sec)

MariaDB [st_db]> select * from st_janghak;
+--------+---------+
| ST_ID  | Money   |
+--------+---------+
| 201401 |  500000 |
| 201402 | 1000000 |
| 201403 | 1500000 |
+--------+---------+
3 rows in set (0.00 sec)

MariaDB [st_db]> alert table st_info add Age int;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'alert table st_info add Age int' at line 1
MariaDB [st_db]> shot tables;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'shot tables' at line 1
MariaDB [st_db]> show tables;
+-----------------+
| Tables_in_st_db |
+-----------------+
| st_grade        |
| st_info         |
| st_janghak      |
+-----------------+
3 rows in set (0.00 sec)

MariaDB [st_db]> alert table st_info add Age int;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'alert table st_info add Age int' at line 1
MariaDB [st_db]> alert table st_info add (Age int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'alert table st_info add (Age int)' at line 1
MariaDB [st_db]> select * from st_info;
+--------+-----------+----------+
| ST_ID  | NAME      | DEPT     |
+--------+-----------+----------+
| 201401 | 이길동    | Game     |
| 201402 | 김길동    | Computer |
| 201403 | 홍길동    | Game     |
+--------+-----------+----------+
3 rows in set (0.00 sec)

MariaDB [st_db]> alert table st_info add AGE int;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'alert table st_info add AGE int' at line 1
MariaDB [st_db]> explain st_info;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ST_ID | int(11)     | NO   | PRI | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| DEPT  | varchar(25) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MariaDB [st_db]> alter table st_info add Age int;
Query OK, 0 rows affected (0.43 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [st_db]> explain st_info;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ST_ID | int(11)     | NO   | PRI | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| DEPT  | varchar(25) | YES  |     | NULL    |       |
| Age   | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MariaDB [st_db]> select * from st_info where ST_DI=201401;
ERROR 1054 (42S22): Unknown column 'ST_DI' in 'where clause'
MariaDB [st_db]> select * from st_info where ST_ID=201401;
+--------+-----------+------+------+
| ST_ID  | NAME      | DEPT | Age  |
+--------+-----------+------+------+
| 201401 | 이길동    | Game | NULL |
+--------+-----------+------+------+
1 row in set (0.00 sec)

MariaDB [st_db]> update st_info set Age=20 where ST_ID=201401;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [st_db]> select * from st_info where ST_ID=201401;
+--------+-----------+------+------+
| ST_ID  | NAME      | DEPT | Age  |
+--------+-----------+------+------+
| 201401 | 이길동    | Game |   20 |
+--------+-----------+------+------+
1 row in set (0.00 sec)

MariaDB [st_db]> update st_info set Age=21 where ST_ID=201402;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [st_db]> update st_info set Age=22 where ST_ID=201403;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [st_db]> select * from st_info;
+--------+-----------+----------+------+
| ST_ID  | NAME      | DEPT     | Age  |
+--------+-----------+----------+------+
| 201401 | 이길동    | Game     |   20 |
| 201402 | 김길동    | Computer |   21 |
| 201403 | 홍길동    | Game     |   22 |
+--------+-----------+----------+------+
3 rows in set (0.00 sec)

MariaDB [st_db]> show tables;
+-----------------+
| Tables_in_st_db |
+-----------------+
| st_grade        |
| st_info         |
| st_janghak      |
+-----------------+
3 rows in set (0.00 sec)

MariaDB [st_db]> explain st_janghak;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| ST_ID | int(11) | NO   | PRI | NULL    |       |
| Money | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

MariaDB [st_db]> select st_info.ST_ID, st_info.NAME, st_info.Age, st_grade.Linux, st_janghak.Money
    -> from st_info, st_grade, st_janghak
    -> where st_info.ST_ID=st_grade.ST_ID and st_info.ST_ID=st_janghak.ST_ID;
+--------+-----------+------+-------+---------+
| ST_ID  | NAME      | Age  | Linux | Money   |
+--------+-----------+------+-------+---------+
| 201401 | 이길동    |   20 |    90 |  500000 |
| 201402 | 김길동    |   21 |    70 | 1000000 |
+--------+-----------+------+-------+---------+
2 rows in set (0.06 sec)

MariaDB [st_db]>

반응형

'프로그래밍 정리 > SQL' 카테고리의 다른 글

[SQL] MariaDB 연습1  (0) 2015.05.08
[SQL] 참조 블로그  (0) 2015.05.08