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

Pyh 1

The document contains instructions for creating and querying tables in a student database. It includes commands to: 1) Create a student table and insert data; create a result table and insert data. 2) Query the tables to retrieve various student data based on conditions like grades, division, email validity. 3) Create triggers on the tables to validate data insertion and prevent deletion of certain records. 4) Disable the created triggers and take backups of the tables and entire database in separate files.

Uploaded by

harshjeswani2209
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)
30 views

Pyh 1

The document contains instructions for creating and querying tables in a student database. It includes commands to: 1) Create a student table and insert data; create a result table and insert data. 2) Query the tables to retrieve various student data based on conditions like grades, division, email validity. 3) Create triggers on the tables to validate data insertion and prevent deletion of certain records. 4) Disable the created triggers and take backups of the tables and entire database in separate files.

Uploaded by

harshjeswani2209
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/ 10

DBPY JOURNAL SYBCA:1

Q.1 Create table student & insert the data into student table.

Ans

2 Create result table & insert data into result table.


ANS

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 1
DBPY JOURNAL SYBCA:1

3 Retrieve students data from both table.


ANS

4 Retrievw STUDENTDATA FROM BOTH TABLE WHOSE PER ARE BETWEEN 92 TO 100.
ANS

5 Retrieve data whose students are in a div 1,3,6.

ANS

6 Retrieve students id,name,email and per whose email address is not valid.

ANS

7 Retrieve all data from both table.

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 2
DBPY JOURNAL SYBCA:1

ANS

8 Retrieve common data from both table.


ANS

9 Retrieve students record whose info. Are not available in result.

ANS

10 Retrieve first 5 data.


ANS

11 Retrieve student info. And find maximum per. Arrange them name wise.

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 3
DBPY JOURNAL SYBCA:1

ANS

12 Retrieve students record arrange them in a city groupwise and city count
should be greater than 3.
ANS

13 Retrieve students data and display approve grade.


ANS

14 Apply Inner join on both table.


ANS

15 Apply left outer join on both table.

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 4
DBPY JOURNAL SYBCA:1

ANS

16 Create trigger on student table to validate students table(before insert).


ANS

17 Create trigger on result table to ansure to delete a record.


ANS

18 Disable above created trigger(all).

ANS
19 Create a saperate file to tack a back-up of student(structure only).
ANS

CREATE TABLE STUDENT


(
SID NUMERIC(10)PRIMARY KEY
SNAME VARCHAR(20)
CITY VARCHAR(20)
CONTACT VATCHAR(20)
EMAIL VARCHAR(20)
CLASS VARCHAR(20)
NAME:BHATHIJA HARSH
ROLL NO:11 pg. 5
DBPY JOURNAL SYBCA:1

DIV VARCHAR(20)
);
CREATE TRIGGER TR_EMAIL_INSERT
BEFORE INSERT
ON STUDENT
begin
select case
when new.EMAIL not like'__%@__%.__%'
'please enter porper
then raise(abort email')
end;
end;
CREATE TABLE STUDENT
(
SID NUMERIC(10)PRIMARY KEY
SNAME VARCHAR(20)
CITY VARCHAR(20)
CONTACT VATCHAR(20)
EMAIL VARCHAR(20)
CLASS VARCHAR(20)
DIV VARCHAR(20)
);
CREATE TRIGGER TR_EMAIL_INSERT
BEFORE INSERT
ON STUDENT
begin
select case
when new.EMAIL not like'__%@__%.__%'
'please enter porper
then raise(abort email')
end;
end;
20 Create a saperate file to tack a back-up of result table(full table).
ANS

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE RESULT
(
RID NUMERIC(10)PRIMARY KEY
SID NUMERIC(10)
PER VARCHAR(20)
FOREIGN KEY (SID) REFERENCES STUDENT(SID)
);
'9
INSERT INTO RESULT 7')
VALUES(30 3 ;
NAME:BHATHIJA HARSH
ROLL NO:11 pg. 6
DBPY JOURNAL SYBCA:1

'9
INSERT INTO RESULT 8')
VALUES(31 2 ;
'9
INSERT INTO RESULT 3')
VALUES(13 1 ;
'3
INSERT INTO RESULT 3')
VALUES(12 4 ;
'5
INSERT INTO RESULT 5')
VALUES(42 5 ;
COMMIT;
21 Create a saperate file to tack a back-up of entire database.
ANS

PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE student1
(
sid numeric(10) primary key
sname varchar(20)
city varchar(20)
contact varchar(10)
email varchar(20)
class varchar(10)
div numeric(10)
);
CREATE TABLE STUDENT
(
SID NUMERIC(10)PRIMARY KEY
SNAME VARCHAR(20)
CITY VARCHAR(20)
CONTACT VATCHAR(20)
EMAIL VARCHAR(20)
CLASS VARCHAR(20)
DIV VARCHAR(20)
);
INSERT INTO STUDENT 'hars 'NAVS '1234567
VALUES(1 h' ARI' 892' 'XYZGMAIL.COM' 'FYBCA'
INSERT INTO STUDENT 'keta 'NAVS '1234567 '[email protected]
VALUES(2 n' ARI' 892' om' 'FYBCA'
INSERT INTO STUDENT 'man '7228001 'manish45@gmail.
VALUES(3 ish' 'surat' 416' com' 'sybca'
INSERT INTO STUDENT 'roha '7228121 '[email protected]
VALUES(4 n' 'chikli' 416' om' 'sybca'
INSERT INTO STUDENT 'moh 'gopal '7228121 '[email protected]
VALUES(5 an' pur' 418' om' 'sybca'
NAME:BHATHIJA HARSH
ROLL NO:11 pg. 7
DBPY JOURNAL SYBCA:1

INSERT INTO STUDENT 'chir 'gopal '7228121 '[email protected]


VALUES(6 ag' pur' 418' m' 'tybca'
INSERT INTO STUDENT 'nikit '7918121 'nikita420@gmail.
VALUES(7 a' 'up' 418' com' 'sybca'
INSERT INTO STUDENT '7918121 '[email protected]
VALUES(8 'om' 'up' 418' m' 'sybca'
INSERT INTO STUDENT 'vats '2118121 'vatsal420@gmail
VALUES(9 al' 'uk' 418' com' 'tybca'
INSERT INTO STUDENT 'bardo '9118121 '[email protected]
VALUES(10 'viki' li' 418' m' 'tybca'
CREATE TABLE RESULT
(
RID NUMERIC(10)PRIMARY KEY
SID NUMERIC(10)
PER VARCHAR(20)
FOREIGN KEY (SID) REFERENCES STUDENT(SID)
);
INSERT INTO RESULT
VALUES(30 3 '97');
INSERT INTO RESULT
VALUES(31 2 '98');
INSERT INTO RESULT
VALUES(13 1 '93');
INSERT INTO RESULT
VALUES(12 4 '33');
INSERT INTO RESULT
VALUES(42 5 '55');
CREATE TRIGGER TR_EMAIL_INSERT
BEFORE INSERT
ON STUDENT
begin
select case
when new.EMAIL not like'__%@__%.__%'
'please enter porper
then raise(abort email')
end;
end;
CREATE TRIGGER TR_RESULT_DELETE
BEFORE DELETE ON RESULT
BEGIN
SELECT
CASE
WHEN OLD.SID=3 THEN 'SOR
RAISE(ABORT RY')
END;
END;
COMMIT;
22 Create a saperate file to tack a back-up of student and result data.

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 8
DBPY JOURNAL SYBCA:1

ANS

INSERT INTO "table" 'NAVSA '1234567


VALUES(1 'harsh' RI' 892' 'XYZGMAIL.COM' 'FYBCA'
INSERT INTO "table" 'NAVSA '1234567 '[email protected]
VALUES(2 'ketan' RI' 892' om' 'FYBCA'
INSERT INTO "table" 'manish '7228001 'manish45@gmail.
VALUES(3 ' 'surat' 416' com' 'sybca'
INSERT INTO "table" '7228121 '[email protected]
VALUES(4 'rohan' 'chikli' 416' om' 'sybca'
INSERT INTO "table" 'mohan 'gopalp '7228121 '[email protected]
VALUES(5 ' ur' 418' om' 'sybca'
INSERT INTO "table" 'gopalp '7228121 '[email protected]
VALUES(6 'chirag' ur' 418' m' 'tybca'
INSERT INTO "table" '7918121 'nikita420@gmail.
VALUES(7 'nikita' 'up' 418' com' 'sybca'
INSERT INTO "table" '7918121 '[email protected]
VALUES(8 'om' 'up' 418' m' 'sybca'
INSERT INTO "table" '2118121 'vatsal420@gmailc
VALUES(9 'vatsal' 'uk' 418' om' 'tybca'
INSERT INTO "table" 'bardoli '9118121 '[email protected]
VALUES(10 'viki' ' 418' m' 'tybca'
INSERT INTO "table"
VALUES(30 3 '97');
INSERT INTO "table"
VALUES(31 2 '98');
INSERT INTO "table"
VALUES(13 1 '93');
INSERT INTO "table"
VALUES(12 4 '33');
INSERT INTO "table"
VALUES(42 5 '55');

23 Create CSV file regaerding to employee:(eid,ename,did,desig,slary).


ANS

24 Create table employee and import emp.csv file data into this table and retrive
data.
ANS create table employee
...> (
...> eid numeric(10),
...> ename varchar(20),
NAME:BHATHIJA HARSH
ROLL NO:11 pg. 9
DBPY JOURNAL SYBCA:1

...> did numeric(10),


...> salary numeric(10)
...> );
sqlite> .mode csv
sqlite> select * from employee;
sqlite> .import emp.csv employee
sqlite> select * from employee;

25 Create emp_bk.csv file to tack a backup of employee table data.


ANS .mode csv
sqlite> select * from employee;
sqlite> .import emp.csv employee
sqlite> select * from employee;

NAME:BHATHIJA HARSH
ROLL NO:11 pg. 10

You might also like