
DBeaverを使ってMySQLのテーブルを作成・削除しよう
MAMPのDBをDBeaverを使って操作しよう!②データベース作成・削除編
前回までDBeaverを使用してDBを作成・削除する方法を見てきました。今回はテーブルの作成と削除をしていきます。
DBeaverを利用したテーブル作成
① Scriptのタブを開いて下記コードを入力
⇒実行箇所にカーソルを合わせて Ctrl+ Enter

create table my_first_db.table(
t_key int primary key auto_increment,
t_id int unsigned default 0 comment 'ID',
t_value varchar(100) default null comment '値'
);
コードを意味を簡単に解説




② データベースを更新するとテーブルが出来る

カラムを追加したいとき

alter table my_first_db.table
add column t_name varchar(20) not null;
alter table my_first_db.table
⇒alter table のあとにDB名とテーブル名を指定
add column t_name varchar(20) not null;
⇒add column のあとに カラム名、データ型、制約

作成時間のカラムの作成
alter table my_first_db.table
add column created_at timestamp not null default current_timestamp;
更新時間のカラムの作成
alter table my_first_db.table
add column updated_at timestamp not null default current_timestamp on update current_timestamp after created_at;
カラムを削除したいとき
alter table my_first_db.table
drop column t_id;
aalter table my_first_db.table
⇒追加と同様にDB名とテーブル名を指定
drop column t_id;
⇒drop column のあとにカラム名
DBeaverを利用したテーブル削除
① 下記コードを実行
drop table my_first_db.table;
⇒実行箇所にカーソルを合わせて

② テーブルが削除されます

MAMPのDBをDBeaverを使って操作しよう!④データレコードの追加・削除
ぜひ参考にしてください!また!