The Sailors-boats-reserves database contains three tables: sailors, boats, and reserves. The sailors table stores sailor details like ID, name, rating, and age. The boats table stores boat details like ID, name, and color. The reserves table stores reservations with a sailor ID, boat ID, and reservation date.
The database is created with CREATE statements that define the tables and columns. Sample data is inserted into the tables. SELECT queries use logical operators like AND, OR, BETWEEN, LIKE, IN, and NOT IN to find matching records from the sailors table based on rating and age criteria.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
58 views2 pages
Worksheet 1
The Sailors-boats-reserves database contains three tables: sailors, boats, and reserves. The sailors table stores sailor details like ID, name, rating, and age. The boats table stores boat details like ID, name, and color. The reserves table stores reservations with a sailor ID, boat ID, and reservation date.
The database is created with CREATE statements that define the tables and columns. Sample data is inserted into the tables. SELECT queries use logical operators like AND, OR, BETWEEN, LIKE, IN, and NOT IN to find matching records from the sailors table based on rating and age criteria.
SQL>CREATE TABLE boats ( bid INTEGER, bname VARCHAR(10),color VARCHAR(10), PRIMARY KEY (bid)) Q3) Reserves ( sid : integer, bid : integer, day : date ) SQL> CREATE TABLE reserves ( sid INTEGER, bid INTEGER, day DATE, PRIMARY KEY(sid, bid, day), FOREIGN KEY(sid) REFERENCES sailors, FOREIGN KEY(bid) REFERENCES boats) SQL> INSERT INTO sailors VALUES (&sid,’&sname’,&rating,&age) SQL> INSERT INTO boats VALUES (&bid,’&bname’,’&color’) SQL>INSERT INTO reserves VALUES(22,101,’ 10/10/201’) Queries using SELECT command with Logical operators AND Q1) find sailor names whose rating <9 and age >40 SQL> SELECT sname FROM sailors WHERE rating<9 AND age>40 Output: OR Q2) find sailor names whose rating <9 or age >40 SQL> SELECT sname FROM sailors WHERE rating<9 OR age>40 Output: NOT Q3) find sailor names whose rating is not 7 SQL> SELECT sname FROM sailors WHERE NOT rating=7 Output: BETWEEN..AND Q4) find sailor names whose age between 40 and 50 SQL> SELECT sname FROM sailors WHERE age BETWEEN 40 AND 50 Output: LIKE Q5)find sailor names conatins letter ‘U’ SQL> SELECT sname FROM sailors WHERE sname LIKE ‘%U%’ Output: IN Q6)find sailor names whose rating is 5 or 7 or 9 SQL> SELECT sname FROM sailors WHERE rating IN (5,7,9) Output: NOT IN Q8)find sailor names whose rating is not 5 or 7 or 9 SQL> SELECT sname FROM sailors WHERE rating NOT IN (5,7,9) Output: