リレーショナブルデータベースを作る #主キー #外部キー

omac:~ hrt0kmt$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.38 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test_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
mysql> create table `table_a` (
    -> `a_id` INT AUTO_INCREMENT,
    -> `name` varchar(255),
    -> `category` varchar(255),
    -> primary key(`a_id`)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> create table `table_b` (
    -> `b_id` int auto_increment,
    -> `user_id` int,
    -> `a_id` int,
    -> `jadge` tinyint,
    -> primary key (`b_id`)
    -> );
Query OK, 0 rows affected (0.01 sec)

テーブル_bのb_idが主キー、a_idが外部キーです。



友達のフリ

友達のフリ

  • ケラケラ
  • J-Pop
  • ¥250