0% found this document useful (0 votes)
15 views

Dbms

Uploaded by

Anuradha Paswan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Dbms

Uploaded by

Anuradha Paswan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

NAME : ANURADHA PASWAN

ROLL NO : 2023UCS1623

EXERCISE 1
Tables used are:
Sailors( sid :integer, sname: varchar , rating :integer, dob: date)

Boats (bid: integer, bname : varchar , color : varchar )

Reserves( sid: integer , bid : integer, date: date, time: time)

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 .

SELECT sname FROM sailors as s , reserves as r , boat as b WHERE


s.sid=r.sid and r.bid=b.bid and b.color=’red’ and b.color =’green’

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.

SELECT * FROM sailors as s WHERE NOT EXISTS(SELECT b.bid FROM


boats as b WHERE NOT EXISTS (SELECT r.bid FROM reserves as r
WHERE r.bid=b.bid and r.sid=s.sid))
Question 7.Find the name and age of the oldest sailor(s).
SELECT * FROM sailors as s WHERE s.dob=(SELECT MIN(s.dob) FROM sailors as
s)
DBMS ASSIGNMENT-2

STEPS :
* Download resources at the end

1. Install MinGW, Code blocks.

Install all basic packages of

MinGW .

2. Set Environment Variable path

3. Open Code blocks, if it doesn’t auto

detect GNU Compiler, Click

Settings->Compiler, set path and C,

C++Compiler

4. Build New Project, choose language

and assign name and save folder

5. Save all SQL header files in

MinGW include .

6. From Code.txt build and run 1st

CODE 1:
#include <iostream>

#include <windows.h>

#include <mysql.h>

using namespace std; int

main()

MYSQL* conn;

MYSQL_ROW row; MYSQL_RES*

res;

conn = mysql_init(0);
conn = mysql_real_connect(conn,"localhost","root","","nsutuniversity",0,NULL,0);

if (conn) //if succeeded cout<<"Connection to database is done"<<endl; else

cout<<"Connection object problem!"<<mysql_error(conn)<<endl;

return 0;

}
7. Paste libmysql.a in MinGW bin 8. Right

click on project name here XamppConnect,

build options and add

linker settings and search directories

9. Add libmysql.dll in

XamppConnect->bin->debug and run

2nd from Code.txt and Check connection

object

CODE 2:

#include <iostream>

#include <string>

#include <windows.h>

#include <mysql.h>

using namespace std; int

main ()

MYSQL* conn;

MYSQL_ROW row;

MYSQL_RES *res;

int qstate; conn =

mysql_init(0);

if(conn)

cout<<"connection object ok, conn="<<conn<<endl; else


cout<<"conn object problem: "<<mysql_error(conn); conn =

mysql_real_connect(conn,"localhost","root","","cocs0302-sec-2",0 ,NULL,0);

if(conn)

cout<<"connected to database cocs0302-sec-2"<<endl;


string SID, Sname ,Rating ,DOB;

cout<<"Enter SID: "<<endl; cin>>SID;

cout<<"Enter Sname: "<<endl; cin>>Sname;

cout<<"Enter Rating: "<<endl; cin>>Rating;

cout<<"Enter DOB: "<<endl; cin>>DOB;

string query="insert into sailors(SID,Sname,Rating,DOB)


values('"+SID+"','"+Sname+"','"+Rating+"','"+DOB+"')";

const char* q = query.c_str();

cout<<"query is: "<<q<<endl; qstate

= mysql_query(conn,q); if(!qstate)

cout<<"record inserted successfully..."<<endl;

else

cout<<"query problem: "<<mysql_error(conn)<<endl; qstate

= mysql_query(conn,"select * from sailors"); if(!qstate)

res = mysql_store_result(conn); while(row=mysql_fetch_row(res))

cout<<"SID"<<row [0] <<" "

<<"Sname"<<row[1]<<" "

<<"Rating"<<row[2]<<" "

<<"DOB"<<row[3]<<endl;

}
else

cout<<"query error: "<<mysql_error(conn)<< endl;

}
}

else

cout<<"Connection object problem!"<<mysql_error(conn)<<endl;

mysql_close(conn); return

0;

10. Connection to Xampp

Database is made from code 3rd code

11. Run 4th Code do SQL query for

displaying all entries in a database.


12. Run 5th code to do SQL query for

inserting new row .

13. Like this change the code for doing

different query like Deletion, Update etc.

NAME : ANURADHA PASWAN


ROLL NUMBER: 2023UCS1623
Assignment- 4
Roll no:-2023UCS1623

Code1 main.txt(for creation of table)

Reflection in database:

Code2 Text2.txt(to insert 5 entries in previous table)


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:

Code5 text5.txt(delete from the table Cricketers_Data)


Reflection in database:
•mpJd
---
1'1UIM I
15 mc_Ol dt
JoO.I<

-- ·-..-
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)

,,_ ...... ·- 1 18rm_U.;1

-·- ·-..-
'""'"'
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

., t ,ow inse ned (Que ry IQOll:O 0007 -


:~)

-,, row .__ (01,wyll)CII.OOOJOM«ll'llk)


!'fSU T_ tti"O Llp loyt t C.S, _ld, l,._ .,_ , )c,1)_14
VAI.UlS lS, 'McO .off' , 1);

tffSU T ltiTO h1p loyH (IEa p_id


, E. ._,. _, lob_ ld) ~~-~.~
Ui, ' l t . . t l - ' , tl;

IE:.dll '°'l!E :.cM J[C, eete PHP tode J

<1' 1 row tinSefled (Que fy took OOOCl7 1«0


fllb. )

ltdll .l'IL M]( FcM J(Cl 'Nt PHP c.od


ol

-,1, owi nwr led (Ou efy ~00 001


s«O fm)

I • .. II 4otll .•Iii¥ • 'HPOOOi"I


• c
'. 1• .. I .._'

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
()

/~(, 6S- --,


. \
. ,u l'\i--
\
"\
-- \
i\ •
' I
\
I
'·~'
--- L\ •
\ I \ I
I -, ----i \ \
.. '
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.

3. List all the employees who are also managers


4. List employee name and salaries , even if the salary value is nor present for employee

You might also like