0% 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.

Uploaded by

Oz G
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

Oz G
Copyright
© © All Rights Reserved
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
You are on page 1/ 2

Sailors-boats-reserves database:

Sailors ( sid : INTEGER, sname : VARCHAR (20), rating : INTEGER,


age :REAL )
SID SNAME RATING AGE
22 DUSTIN 7 45
31 LUBBER 8 55.5
58 RUSTY 10 35
Boats ( bid : INTEGER, bname :VARCHAR(10), color : VARCHAR(10) )
BID BNAME COLOR
101 INTERLAKE BLUE
102 INTERLAKE RED
103 CLIPPER GREEN
104 MARINE RED
105 BALZE BLUE

Reserves ( sid : INTEGER, bid : INTEGER, day : DATE )


SID BID DAY
22 101 10/10/2011
31 103 01/04/2011
22 103 16/06/2011
58 104 06/05/2011
31 105 06/07/2011

Sailors-boats-reserves realtion schemas


Creating sailors-boats-reserves database:
Q1) Sailors ( sid : integer, sname : string, rating : integer, age : real )
SQL> CREATE TABLE sailors ( sid INTEGER, sname VARCHAR(10),
rating INTEGER, age REAL, PRIMARY KEY (sid))

Q2) Boats ( bid : integer, bname : string, color : string )


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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy