Relational databases organize data in tables. Each table in the database contains information about objects of concern and relationships that objects have with other objects. So, one can associate a first-order logic predicate with each table.
STUDENT | |
---|---|
SID | NAME |
1111 | Jones |
2222 | Smith |
3333 | Blake |
4444 | Damon |
5555 | Bell |
COURSE | |
---|---|
CNO | TITLE |
CSc2310 | Java |
CSc2510 | Theory |
CSc4710 | Database |
ENROLL | ||
---|---|---|
SID | CNO | GRADE |
1111 | CSc2310 | F |
1111 | CSc2510 | F |
2222 | CSc2510 | A |
2222 | CSc4710 | B |
3333 | CSc2310 | A |
3333 | CSc2510 | A |
3333 | CSc4710 | F |
We can associate predicates student, course, and enroll with the three tables. The arities of the relations correspond to the number of columns in the table.
To use the system run the following 2 commands the first time you sign in:
cp ~raj/.cshrc . source .cshrcand to run the query system, execute the following command:
java edu.gsu.cs.ra.RA ~raj/enrollDBYou will see a RA> prompt where you can enter a query. To exit the query system, enter the exit; command.
Now, some query examples:
project[NAME](student join select[CNO='CSc2510'](enroll));
project[CNO,TITLE](select[NAME='Smith'](student) join course join enroll);
project[NAME](select[C1<>C2](student join rename[SID,C1,G1](enroll) join rename[SID,C2,G2](enroll)));
project[NAME](student join select[CNO='CSc2510' and GRADE='A'](enroll));
project[NAME](student join (project[SID](student) minus project[SID](enroll)));
project[NAME](student join (project[SID](select[CNO='CSc2310'](enroll)) union project[SID](select[CNO='CSc2310'](enroll)) ) );
Here is a screen capture of running the above queries on the system:
[~][9:03pm] java edu.gsu.cs.ra.RA ~raj/enrollDB RA> student; STUDENT(SID:INTEGER,NAME:VARCHAR) Number of tuples = 5 1111:Jones: 2222:Smith: 3333:Blake: 4444:Damon: 5555:Bell: RA> course; COURSE(CNO:VARCHAR,TITLE:VARCHAR) Number of tuples = 3 CSc2310:Java: CSc2510:Theory: CSc4710:Database: RA> enroll; ENROLL(SID:INTEGER,CNO:VARCHAR,GRADE:VARCHAR) Number of tuples = 7 1111:CSc2310:F: 1111:CSc2510:F: 2222:CSc2510:A: 2222:CSc4710:B: 3333:CSc2310:A: 3333:CSc2510:A: 3333:CSc4710:F: RA> project[NAME](student join select[CNO='CSc2510'](enroll)); temp2(NAME:VARCHAR) Number of tuples = 3 Jones: Smith: Blake: RA> project[CNO,TITLE](select[NAME='Smith'](student) join course join enroll); temp3(CNO:VARCHAR,TITLE:VARCHAR) Number of tuples = 2 CSc2510:Theory: CSc4710:Database: RA> project[NAME](select[C1<>C2](student join rename[SID,C1,G1](enroll) join rename[SID,C2,G2](enroll))); temp5(NAME:VARCHAR) Number of tuples = 3 Jones: Smith: Blake: RA> project[NAME](student join select[CNO='CSc2510' and GRADE='A'](enroll)); temp2(NAME:VARCHAR) Number of tuples = 2 Smith: Blake: RA> project[NAME](student join (project[SID](student) minus project[SID](enroll))); temp4(NAME:VARCHAR) Number of tuples = 2 Damon: Bell: RA> project[NAME](student join RA> (project[SID](select[CNO='CSc2310'](enroll)) union RA> project[SID](select[CNO='CSc2510'](enroll)) )); temp6(NAME:VARCHAR) Number of tuples = 3 Jones: Smith: Blake: RA> exit; [~][9:04pm]