SQL examples
Create a relation:
- SQL> create table "samplef".
- SQL> attribute("number", 1, "integer", 7).
- SQL> attribute("yomi", 2, "char", 10).
- SQL> partitions(flat,"../../common/newrel/samplef").
- SQL> end.
Create a relation with Btree index:
- SQL> create table "sampleb".
- SQL> attribute("number", 1, "integer", 7).
- SQL> attribute("yomi", 2, "char", 10).
- SQL> partitions(btree, "../../common/newrel/btree/sampleb",1,1).
- SQL> parallel_disk({2,"../../common/newrel/btree/sasmpleb",
"../../common/newrel/btree1/","../../common/newrel/btree2/"}).
- SQL> primary_key(int, 1).
- SQL> page(4, 200, 40).
- SQL> end.
Drop a relation:
- SQL> drop table "samplef".
- SQL> end.
Insert tuples:
- SQL> insert into "samplef".
- SQL> values([1,"foo"]).
- SQL> values([2,"hoge"]).
- SQL> values([3,"bar"]).
- SQL> values([4,"afo"]).
- SQL> end.
Delete tuples:
- SQL> delete "samplef".
- SQL> where "number" >= [3].
- SQL> end.
Declaration of a transaction:
- SQL> start transaction.
- SQL> insert into "samplef".
- SQL> values([5,"bfo"]).
- SQL> end.
- SQL> commit transaction.
Abort the transaction:
- SQL> start transaction.
- SQL> delete "samplef".
- SQL> where "number" = [1].
- SQL> end.
- SQL> rollback transaction.
Get relation without conditions:
- SQL> select * .
- SQL> from "emp".
- SQL> end.
Selection1:
- SQL> select "ename", "job", "sal", "comm".
- SQL> from "emp".
- SQL> where "job"=["manager"] or ( "sal" > [3000] and "deptno" = [10] ).
- SQL> end.
Selection2:
- SQL> select "ename", "deptno".
- SQL> from "emp".
- SQL> where "deptno" in [10,30].
- SQL> end.
Join (nested):
- SQL> select "empno", "job", "deptno".
- SQL> from "emp".
- SQL> where "deptno" = next.
- SQL> select "deptno".
- SQL> from "dept".
- SQL> where "loc" = ["newyork"].
- SQL> end.
Join:
- SQL> select * .
- SQL> from "emp", "dept".
- SQL> where "emp"-"deptno" = "dept"-"deptno".
- SQL> end.
Count:
- SQL> select count.
- SQL> from "emp".
- SQL> where "job" = ["manager"].
- SQL> end.
Group by
- SQL> select "job", avg("sal").
- SQL> from "emp".
- SQL> group by "job".
- SQL> end.
Please find examples in "common/input"