LoginSignup
4
1

SQLite入門:データベースファイル作成からテーブル作成の流れ!よく使うコマンド

Last updated at Posted at 2024-02-24

データベースファイル作成からテーブル作成の流れ

⚫︎リポジトリの直下ディレクトリからデータベースファイルを作成したいディレクトリに移動する。

今回はdbディレクトリに移動する

cd db

⚫︎dbディレクトリの中でsqlite3を動作する。

sqlite3

⚫︎customer.sqlite3という名前のデータベースファイルを作成

sqlite> .open --new customer.sqlite3

⚫︎テーブル作成

sqlite> CREATE TABLE customer(id INTEGER PRIMARY KEY, name TEXT NOT NULL);

⚫︎テーブルが作成できていることを確認

sqlite> .ta

よく使うコマンド

⚫︎sqliteから抜ける

下のコマンドか、control + Dでsqliteから抜けることができます。

sqlite> .exit

⚫︎テーブルを作成した際の定義を見たい時に使用

sqlite> .schema customer

⚫︎すでに作成したテーブルの定義を削除

sqlite> drop table customer

⚫︎テーブルに入っている中身を見たい時

sqlite> SELECT * FROM customer;

参考文献

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