LoginSignup
0
0

More than 1 year has passed since last update.

phpMyAdminで外部キーを設定する方法

Posted at

・resultテーブルを作る
・カラム名、データ型、桁数を決める
・主キーを作る
・外部キーを作る(customerテーブルのIDを参照する)

CREATE TABLE
    result (
        ID INTEGER(11),
        customer_id INTEGER(255),
        checkdate DATE,
        weight TEXT,
        height TEXT,
        bloodpressure TEXT,
        created_at datetime  default current_timestamp,
        updated_at timestamp default current_timestamp on update current_timestamp,
        PRIMARY KEY (ID),
        FOREIGN KEY (customer_id)
        REFERENCES customer (ID)

    );

ハマったところ
・PRIMARY KEY (ID)の後には「,」が必要
・FOREIGN KEY (customer_id)の後には「,」はいらない

PRIMARY KEY (ID),
FOREIGN KEY (customer_id)
REFERENCES customer (ID)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0