きっかけ
「MySQLのダミー用データベースがほしいな」
「Dummy data for MYSQL databaseとか使えばいいのかな。使ったことないからちょっと面倒。」
「ChatGPT使ってみるか」
やったこと
ChatGPTにお願いする
Promptに以下のように入力しました。
Give me the code of MySQL in order to generate dummy database.
爆速で解答とコードが返ってきました。
Here is some example code that you can use to generate a dummy database in MySQL:
-- Create a new database
CREATE DATABASE dummy_db;
-- Select the dummy database
USE dummy_db;
-- Create a new table called 'employees'
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255),
last_name VARCHAR(255),
email VARCHAR(255),
age INT
);
-- Insert some dummy data into the 'employees' table
INSERT INTO employees (first_name, last_name, email, age)
VALUES ('John', 'Doe', 'john.doe@example.com', 35),
('Jane', 'Doe', 'jane.doe@example.com', 32),
('Bob', 'Smith', 'bob.smith@example.com', 42),
('Samantha', 'Johnson', 'samantha.johnson@example.com', 29);
This code will create a new database called "dummy_db", and create a table called "employees" with columns for id, first_name, last_name, email, and age. It also inserts some dummy data into the table.
You can also use the SELECT statement to check the data.
SELECT * FROM employees;
Please note that this is a basic example and you can adjust it to your needs.
MySQLでSQLクエリを実行してみた
ubuntuでMySQLを実行してみました。
$ vim dummy.sql
でChatGPTが作ってくれたSQLをコピペしました。
$ mysql < dummy.sql
MySQLを起動し,クエリを実行してみたところ,ちゃんとデータベースができてました。
終わりに
ChatGPTの使い方としてはあまりにも小さすぎる気がしますが,ひとまず私もChatGPTの恩恵を感じることができました。