DB
Pro added layer of security that can be placed on the database from the data functionality making it easier to manage, document, and maintain improved performance multiple client applications to have consistent database routines Con to man…
自テーブル各レコードの特性を 単純な射影や選択では比較できない場合に使う ここでは CASE, 相関サブクエリ, 内部/外部結合などに言及しないとする (Web 記事や書籍を眺めてみたのだが、なかなか扱いがよくわからん構文 勉強しきれてないが、これ使うのであ…
(一番)使われるのは「レコードの存在チェック」 Web 記事を色々眺めて、私なりの答え (業務システムの SQL を見ていると「このオペレーションは、いつ、何のために使うのか」 を見失うので一回整理したい) 例 利用者が存在し、各属性を持つ 利用者 ID 年齢(0…
StackOverflow より引用及び翻訳(意訳 加筆) より正確な内容は本記事下段のリンク先参照 view はいくつか良いものを提供してくれる 1. View は複雑さを隠すことができる 何個かテーブルを結合したり、複雑な計算したり、 複雑ロジックを組んだクエリが必要な…
プログラマのための SQL 第4版 より 自分用のまとめ GROUP BY 演算の目的 複数行を集約キーでグループごとにまとめ各グループの特性を示す行を返すこと 返ってきた行は そのグループの特性を示すものであり(*1) グループに存在する特定行の性質を示すもので…
Statement 単純な実行計画を行いたい時(select * from ... を 1 回だけ など) PreparedStatement 複数回に渡る実行計画を行いたい時, ? のパラメーター解析を使いたい時(2 番目記事参照) JDBC - Statements, PreparedStatement and CallableStatementwww.tut…
基本的に、connection は開いたら閉じる 門外不出のOracle現場ワザ 第5章
ALTER TABLE tablename ADD CONSTRAINT constraint_name CHECK でCHECK制約使えるか PostgreSQL > ○ MySQL > △ Sqlite3 > × MySQL SQL は parse する、けど、どのストレージエンジンもこれを有効化しません 細工をしたら有効化しますよ(→ !?) CHECK constrai…
ALTER TABLE tablename ADD CONSTRAINT を 新規テーブルへ実行 ALTER TABLE 可能 CREATE TABLE projects ( projectname text NOT NULL, membernum integer NOT NULL ); ALTER TABLE projects ADD CONSTRAINT projects_membernum_check CHECK(membernum BETWE…
「アプリケーション層の validation は、不正値入力の『通知』に留め」 「データの整合性 はデータ層が担保しよう」 って Dan Chak さんが言ってた(覚えがあるので要復習) CREATE TABLE users ( name text NOT NULL, receivemailflag INTEGER NOT NULL DEFAU…
RIGHT もやることは変わらない LEFT OUTER JOIN の内部処理 CROSS JOIN で集合の組合せ(順列テーブル) を作成する ON 条件に合致する集合を ↑ から走査し、合致すればその集合を保持する 条件に合致しなければ(FALSE か UNKNOWN) [X] を実行 [X] 保存対象の…
INNER JOIN の内部処理 CROSS JOIN で集合同士の組合わせ(順列テーブル)を作成する ON 条件に合致する集合を ↑ から、一つ一つ走査する 条件合致した集合を抽出し、これを結果の集合とする 前提テーブルとデータ(RDBMS == PostgreSQL) CREATE TABLE vendors …
親テーブルと子テーブルがありました 親テーブルの外部キーで参照されるキーの値が変更(削除、更新)されました 子テーブルの参照するキーの値はどうしますか リンク参照 連鎖参照整合性制約
経験者の意見 Composite primary keys versus unique object ID fieldstackoverflow.com
PostgreSQL 外部参照留め書き 参照する側 が 参照される側 に無い要素を insert, update をすることはできない https://www.postgresql.jp/document/8.1/html/tutorial-fk.html
If use 'group by', set will be divided to subgroups. implements CREATE TABLE membeers ( name text, age integer, home text ); -- abbreviated insertion... SELECT * FROM members; name | age | home ---------+-----+--------- shimano | 25 | tott…
description(snippet from reference) The SQL HAVING Clause is used in combination with the GROUP BY Clause to restrict the groups of returned rows to only those whose the condition is TRUE. reference SQL: HAVING Clause
related to NOT IN ; sql - Red > Green > Refactor > Red snippet from reference >>-+-expression1--+-----+--IN--+-(--fullselect1--)---------+-+->< | '-NOT-' | .-,---------------. | | | | V | | | | +-(------expression2---+--)-+ | | '---express…
snippet from reference 4 Concepts 4.1 Data types A data type is a set of representable values. The logical representation of a value is a <literal>. The physical representation of a value is implementation-dependent. A value is primitive in that it</literal>…
snippet from reference The term cardinality actually has two different meanings depending on the context of it’s usage one meaning is in the context of data modeling and the other meaning is in the context of SQL statements. . . when the w…
snippet from reference 8.8 <exists predicate> Function Specify a test for a non-empty set. Format <exists predicate> ::= EXISTS <table subquery> General Rules 1) Let T be the result of the <table subquery>. 2) If the cardinality of T is greater than 0, then the result of the <exists predicate> is tr…</exists></table></table></exists></exists>
solution to odd action at NOT IN (...only result) (avoid record If NULL is included) SELECT * FROM members; id | name | age | home ----+---------+-----+--------- 1 | takagi | 23 | tottori 2 | kinashi | 19 | tottori 3 | itano | 20 | osaka 4…
Difference between in and any operators in sqlstackoverflow.com
check whether exists NULL when use NOT IN (related to: return value of IN predicate ; sql - Red > Green > Refactor > Red) create table member ( memberid serial, name text, age integer, home text, PRIMARY KEY(memberid) ); SELECT * FROM memb…
use serial official PostgreSQL: Documentation: 9.4: Numeric Types unofficial PostgreSQL - AUTO INCREMENTwww.tutorialspoint.com CREATE TABLE table_names ( id serial, name text, PRIMARY KEY(id) ); INSERT INTO table_names (name) VALUES ('taro…
NULL values represent missing unknown data. SQL NULL Values - IS NULL and IS NOT NULL
Why in SQL NULL can't match with NULL?stackoverflow.com
Visual Representation of SQL Joins - CodeProject
A Visual Explanation of SQL Joins
http://jpn.teradata.jp/library/nyumon/ins_1905.html