0
0

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 3 years have passed since last update.

MySQL基礎(CREATE, INSERT)

Posted at

postsデータベース作成
message, likesテーブル作成方法

ターミナル
DROP TABLE IF EXISTS posts; --もし、postsがあれば削除する
CREATE TABLE posts (
 message VARCHAR(140), --文字制限
 likes INT --整数
);

DESC posts; --postsテーブルの確認
SHOW TABLES; --データベースの確認

INSERT INTO posts (message, likes) VALUES --
  ('Thanks', 12), 
  ('Arigato', 4);

SELECT * FROM posts; --テーブル名(posts)中から全てのレコードを取ってくる

実行結果

+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| message | varchar(140) | YES  |     | NULL    |       |
| likes   | int(11)      | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
+-----------------+
| Tables_in_myapp |
+-----------------+
| posts           |
+-----------------+
+---------+-------+
| message | likes |
+---------+-------+
| Thanks  |    12 |
| Arigato |     4 |
+---------+-------+
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?