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

【SQL】テーブル作成、テストデータ投入(bulk)、データクエリ、テーブルドロップのメモ

2
Posted at

はじめに

  • SQLはほぼselectしか打たないし、selectも簡単なleft join、inner join、like、limit、whereしかわからない。

問題

  • select以外のSQL全然文法知らないので以下を調べたり実行して確認した
    • int4にする方法
    • uuidの値を入れる方法
    • create table文
    • PKの指定方法

解決

  • 以下の感じでとりあえずテストデータ作成したりできる
create table hogepiyos(
  id uuid NOT NULL,
  title varchar(255) NOT NULL,
  time int4 NOT NULL,
  primary key (id)
) 

insert into hogepiyos(
  id, title, time
) values 
  (gen_random_uuid(), 'hoge', 10), 
  (gen_random_uuid(), 'fuga', 2), 
  (gen_random_uuid(), 'piyo', 4)

select * from hogepiyos

-- drop table hogepiyos

終わりに

  • select以外の、selectもgroup byとか、where in (select column_name from hoges~~)とか、実行計画読むとか今後やっていきたい
2
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
2
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?