Dbms
Dbms
ROLL NO : 2023UCS1623
EXERCISE 1
Tables used are:
Sailors( sid :integer, sname: varchar , rating :integer, dob: date)
SAILORS:
BOATS:
RERSERVES:
Question 1 . Find sailors who have reserved at least one boat.
SELECT * FROM sailors as s , reserves as r ,boats as b where s.sid=r.sid
and r.bid =b.bid
Question 2. Find names of sailors who have reserved a red or a green boat in
the month of march.
SELECT sname FROM sailors as s , reserves as r, boats as b WHERE
s.sid =r.sid and r.bid =b.bid and month(r.date)=3 and (b.color=’red’ or
b.color=’green’)
Question 3. Find names of sailors who have reserved a red and a
green boat .
Question 4. Find sid of sailors who have not reserved a boat after jan
2018.
SELECT sid FROM sailors as s , reserves as r, boats as b WHERE sid
NOT IN (SELECT sid FROM sailors as s , reserves as r , boats as b
WHERE s.sid=r.sid and r.bid=b.bid and r.date>’2018-01-01”)
Question 5. Find sailors whose rating is greater than that of all the
sailors named “john”.
SELECT * FROM sailors as s WHERE s.rating >(SELECT MAX(s2.rating)
FROM sailors as s2 WHERE s2.sname=’john’)
Question 6. Find sailors who have reserved all boats.
STEPS :
* Download resources at the end
MinGW .
C++Compiler
MinGW include .
CODE 1:
#include <iostream>
#include <windows.h>
#include <mysql.h>
main()
MYSQL* conn;
res;
conn = mysql_init(0);
conn = mysql_real_connect(conn,"localhost","root","","nsutuniversity",0,NULL,0);
return 0;
}
7. Paste libmysql.a in MinGW bin 8. Right
9. Add libmysql.dll in
object
CODE 2:
#include <iostream>
#include <string>
#include <windows.h>
#include <mysql.h>
main ()
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES *res;
mysql_init(0);
if(conn)
mysql_real_connect(conn,"localhost","root","","cocs0302-sec-2",0 ,NULL,0);
if(conn)
= mysql_query(conn,q); if(!qstate)
else
<<"Sname"<<row[1]<<" "
<<"Rating"<<row[2]<<" "
<<"DOB"<<row[3]<<endl;
}
else
}
}
else
mysql_close(conn); return
0;
Reflection in database:
Code3 text3.txt(Print all values of Column Frits_name and Country for the table
Cricketers_Data)
Code4 text4.txt(Update Country for the table Cricketers_Data)
Reflection in database:
-- ·-..-
j00_9U pffrito t
,,._
_,. plan_ dncrlp tion
1 181m ~Ii&
··-
3 bnQ tann_d isabliry
15 mc._dadG
"""' ,...._
,...,,.
,,_
""""
20,.. ..
141ud ill
15mc da<»
151M_ _dada
--- ·-
......,
.....
'*"' --
,...._...,
1 1i&ml_W.
2 SIOO J)Uf~
3 lon;._lllnn_diutliily
,,_
10 llftlrdo
_,.·- 1 1e1m_Ue
·-
1 lfffol_Me
,,_
20 - 91
141"°
15 mc_c»c11
1511'1(d,adl-
,,_
10 /Ulsdo
---
"""".'
...... ,....__
1 . .,.._...
2 SIOOJMCMM
3 long _lem l_~
111:11T1_YI)
-·- ·-..-
'""'"'
20 .... ,,.,_ 3 klng_le fm
·--
1' ludel
1 """'-" "'
I~ ,nc_o. c»
15~c a.s.
10 .,._do ,...._
3 lon;._l llnn_d !Ublly
Cl
NfrMt : ltN URJ¥)HA fO/JwC//Y1 , c.lA-s91Alc.
oa te _~ -
~ N o .' &JJ~~ UU!&d.!£ Page
- t)• r
_ _ _r/ 7 J _ ~ -- -~ )L _1 k] ~~ ~L -- -7
/N _f ::_ :_ -= l_ ~~ .
/,
L_ &2
~--ahta
u-~ ill~~-------
~(-~
-L\lU L_t~f_
----tt-~
'
I~
rl-o
-- - ~:: :::: t!:: :=: - ==== ==== == ==== ==== == == ====== ============;==========1
~=::::::::::::::=:==============U)Ji/>1T€!'--i _CUi _t /,p ,r 1= L{)(,wt1- ~ - - -
-- H ~ ~ 0 ~ c ± t~ lJ .w jJ ---
---
• ~-~ b_ t{, ,r> ----
d(JVJ?fd ------
----tf-~~~ -- 1 -'-
-~ -b 9 ~ tA ~ .J -. .C ..
1' I
. - '
'I '
/1 .l I
'.
\
I
/A,
~
l1 I .....
c<
I
\
th
' I
\ \ \ \
I
'
I
I
'·
I •
' '°4
f '.
' \
;2- l I
\
t
\
,. 2
I ~
I I
' . ) I
'I '
-\ \
• I
, kr\l Ctlf t i.J IOl 4 har m
I 4 , ' \
. .. '
, ( I• , 'i • . • ,.
•\ ' ' - t
.,
•, - '••j I /. '\<, \ \ •,. ;" ) ~, ! rl r'
r -5) f)
- ---- ..Q ._E LT A~
~
Date~
Pg No.
------- ___.,. I
\ , I
\' ' .
I t,
'
I\
iI
I.
.
l
ad
If A
'- r.
r I',
. .. \
·, ' I
. .\
\. ffO -~ L - \.
\ \
\
'
£q-o/J, - I\ I'. (
L.- \ ' \.
A6 f-2-2- '• .. \ r , , 1, ' i I \ '
/J7- I l. ' ' \
\
{It .(, %' I (.• \
"'· J
I~
I
()
fu t
\
\. I
, \
1 { \
I \
I, t6 I' -"""y I
I t
• I' ( -~
I
' I
..
"
I~
{J t \
.,..
:\ ~ ~ '\ t.- ~... ~
- \
. f)
\ I
.. .
Name: Anuradha Paswan
Roll no:2023UCS1623
LAB -TEST
1.List out records that are present in one table
1. List all the Employer , who are not working on any project
2. List project wise count of Employees.