달력

42024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

mysql> create table aa (
    ->   idx int unsigned not null auto_increment,
    ->   name varchar(20) not null,
    ->
    ->   Constraint pk_idx PRIMARY KEY(idx)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> create table bb(
    ->    idx int unsigned not null auto_increment,
    ->    parent int unsigned not null,
    ->    name varchar(20) not null,
    ->    primary key(idx)
    -> );
Query OK, 0 rows affected (0.04 sec)

mysql> insert into aa values(null, '111');
Query OK, 1 row affected (0.00 sec)

mysql> insert into aa values(null, '222');
Query OK, 1 row affected (0.00 sec)

mysql> insert into aa values(null, '333');
Query OK, 1 row affected (0.00 sec)

mysql> select * from aa;
+-----+------+
| idx | name |
+-----+------+
|   1 | 111  |
|   2 | 222  |
|   3 | 333  |
+-----+------+
3 rows in set (0.00 sec)

mysql> insert into bb values(null, 2, 'bb222');
Query OK, 1 row affected (0.00 sec)

mysql> insert into bb values(null, 2, 'bb222');
Query OK, 1 row affected (0.00 sec)

mysql> insert into bb values(null, 2, 'bb222');
Query OK, 1 row affected (0.00 sec)

mysql> select * from bb;
+-----+--------+-------+
| idx | parent | name  |
+-----+--------+-------+
|   1 |      2 | bb222 |
|   2 |      2 | bb222 |
|   3 |      2 | bb222 |
+-----+--------+-------+
3 rows in set (0.00 sec)

mysql> delete aa, bb from aa, bb where aa.idx = bb.parent;
Query OK, 4 rows affected (0.00 sec)

mysql> select * from aa;
+-----+------+
| idx | name |
+-----+------+
|   1 | 111  |
|   3 | 333  |
+-----+------+
2 rows in set (0.00 sec)

mysql> select * from bb;
Empty set (0.00 sec)

mysql>

'SQL' 카테고리의 다른 글

[펌] MySQL의 SQL  (0) 2005.01.14
STOP WORD  (2) 2005.01.14
[펌] [오라클] 인덱스  (0) 2004.09.22
[mysql] ifnull  (0) 2004.09.16
오라클 설치 잘 나온 사이트  (0) 2004.09.02
Posted by tornado
|