SQL examples
Create a relation based on KLIC I/O:
- SQL> create table work.
- SQL> attribute("number", 1, "integer", 4).
- SQL> attribute("name", 2, "char", 20).
- SQL> partitions(flat,"../../common/newrel/work").
- SQL> end.
Create a relation based on page I/O:
- SQL> create table workp.
- SQL> attribute("number", 1, "integer", 4).
- SQL> attribute("name", 2, "char", 20).
- SQL> partitions(page,"../../common/newrel/workp").
- 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.
Insert tuples:
- SQL> insert into work.
- SQL> values([1,"foo"]).
- SQL> values([2,"hoge"]).
- SQL> values([3,"bar"]).
- SQL> values([4,"afo"]).
- SQL> end.
Delete tuples:
- SQL> delete.
- SQL> from work.
- SQL> where number=2.
- SQL> end.
Declaration of a transaction:
- SQL> start transaction.
- SQL> insert into work.
- SQL> values([5,"bfo"]).
- SQL> end.
- SQL> commit transaction.
Rollback the sub-transaction:
- SQL> start transaction.
- SQL> delete
- SQL> from work.
- SQL> where number=1.
- SQL> end.
- SQL> rollback transaction.
Abort the root transaction:
- SQL> insert into work.
- SQL> values([5,"bfo"]).
- SQL> end.
- SQL> abortall transaction.
Drop a relation:
- SQL> drop table work.
- SQL> end.
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, dept.
- SQL> from emp.
- SQL> where dept in [20, 30].
- SQL> end.
Join (nested):
- SQL> select empno, job, dept.
- SQL> from emp.
- SQL> where dept = next.
- SQL> select dept.
- SQL> from dept.
- SQL> where location = next.
- SQL> select location.
- SQL> from location.
- SQL> where name = "Sighthill".
- SQL> end.
Join:
- SQL> select * .
- SQL> from emp, dept.
- SQL> where emp.dept = dept.dept.
- 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.
Add a rule
- SQL> defrule "tmp".
- SQL> when retrieve(work).
- SQL> if true.
- SQL> then immidiate.
- SQL> echo "warning".
- SQL> end.
Delete a rule
- SQL> undefrule.
- SQL> where name="tmp".
- SQL> end.
Please find examples in "common/input"