「Sqlite/テーブル」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→テーブル型について) |
|||
| (同じ利用者による、間の2版が非表示) | |||
| 行8: | 行8: | ||
> .tables | > .tables | ||
users | users | ||
| + | |||
| + | ==テーブル定義一覧== | ||
| + | > .schema | ||
| + | CREATE TABLE users(id, name); | ||
| + | CREATE TABLE users2(id integer, name text); | ||
| + | |||
| + | ==テーブル型について== | ||
| + | NULL, INTEGER(1,2,3,4,6,8バイト)、REAL(8バイト)、TEXT(UTF-8、UTF-16/16LE)、BLOBの5種類だけ。 | ||
| + | |||
| + | 参考:https://www.wcguru.net/sqlite3-datatype/ | ||
| + | |||
| + | ==行ごとのテーブル型について== | ||
| + | <pre> | ||
| + | sqlite> insert into users3 values(1, 'taro'); | ||
| + | sqlite> insert into users3 values(100000, '100ro'); | ||
| + | sqlite> insert into users3 values("hoge", 'hogero'); | ||
| + | sqlite> select id, typeof(id), name, typeof(name) from users3; | ||
| + | 1|integer|taro|text | ||
| + | 100000|integer|100ro|text | ||
| + | hoge|text|hogero|text | ||
| + | </pre> | ||
| + | 行ごとに型が変更されてる様子。 | ||
2020年2月26日 (水) 17:42時点における最新版
テーブル作成
create table users(id, name);
テーブル作成カラム付き
create table users2(id integer, name text);
テーブル一覧
> .tables users
テーブル定義一覧
> .schema CREATE TABLE users(id, name); CREATE TABLE users2(id integer, name text);
テーブル型について
NULL, INTEGER(1,2,3,4,6,8バイト)、REAL(8バイト)、TEXT(UTF-8、UTF-16/16LE)、BLOBの5種類だけ。
参考:https://www.wcguru.net/sqlite3-datatype/
行ごとのテーブル型について
sqlite> insert into users3 values(1, 'taro');
sqlite> insert into users3 values(100000, '100ro');
sqlite> insert into users3 values("hoge", 'hogero');
sqlite> select id, typeof(id), name, typeof(name) from users3;
1|integer|taro|text
100000|integer|100ro|text
hoge|text|hogero|text
行ごとに型が変更されてる様子。
