1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ChatGPTにMySQLのダミー用データベースを作成してもらった

Last updated at Posted at 2023-01-24

きっかけ

「MySQLのダミー用データベースがほしいな」
Dummy data for MYSQL databaseとか使えばいいのかな。使ったことないからちょっと面倒。」
「ChatGPT使ってみるか」

やったこと

ChatGPTにお願いする

Promptに以下のように入力しました。

Give me the code of MySQL in order to generate dummy database.

爆速で解答とコードが返ってきました。

image.png

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を起動し,クエリを実行してみたところ,ちゃんとデータベースができてました。
image.png

終わりに

ChatGPTの使い方としてはあまりにも小さすぎる気がしますが,ひとまず私もChatGPTの恩恵を感じることができました。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?