0% found this document useful (0 votes)
29 views7 pages

App Assignment 5

Uploaded by

Riya Bharathwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

App Assignment 5

Uploaded by

Riya Bharathwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
5115722, 835 PM In [1]: In [7]: In [8]: [APP EXPT-5 - Jupyter Notebook APP EXPERIMENT 5 RA2011027010062 RIYA BHARATHWAJ AIM-TO IMPLEMENT DECLARATIVE PROGRAMMING PARADIGM USING SQLITE 3 41) Create the below table and execute the insert, update and the below select statements. i) Write a query to display the total number of recipes available with the descr “Chinese” Il) Write a query to display the Id, name of the recipes with chef_id "BL000002.. ii) Write a query to display the description of the recipes whose name begins with ‘P’. import sqlite3 conn = sqlite3.connect(‘restaurant.db') print ("Database created successfully") conn.execute('' ‘CREATE TABLE RECIPES (ID INT PRIMARY KEY NOT NULL, NAME char(4@@) NOT NULL, DESCRIPTION TEXT NOT NULL, CATEGORY_ID INT NOT NULL, CHEF_10 INT NOT NULL, CREATED DATETIME) ''*) print(“Table created successfully") conn.close() Database created successfully Table created successfully import sqlite3 conn=sqlite3. connect ('restaurant.db') conn.execute("INSERT INTO RECIPES VALUES (1, "BUTTER CHICKEN’, "INDIAN" ,24567,546, ' conn.execute("INSERT INTO RECIPES VALUES (2, "PIZZA, ‘ITALIAN’ ,98763,52, ‘2021-07 conn.execute("INSERT INTO RECIPES VALUES (3, "MANCHURIAN' , ‘CHINESE’ ,12984,23@, ‘201 conn.commit() print("Values inserted") conn.close() values inserted conn=sqlite3.connect('restaurant.db') cursor=conn.execute("SELECT * FROM RECIPES") for i in cursor: print(i) (1, ‘BUTTER CHICKEN’, ‘INDIAN’, 24567, 546, ‘2020-11-05') (2, ‘PIZZA’, ‘ITALIAN’, 98763, 52@, ‘2021-07-15 11:25::') (3, 'MANCHURTAN', ‘CHINESE’, 12984, 230, ‘2018-05-18 12') localhost8891inatebookslanacondasiAPP EXPT-S.pyn wr 5115722, 835 PM In [9]: In [10]: In [11]: In [13]: In [14]: [APP EXPT-5 - Jupyter Notebook conn=sqlite3.connect('restaurant.db') cursor=conn.execute("SELECT * FROM RECIPES where DESCRIPTION ' CHINESE") for i in cursor: print(i) (3, 'MANCHURIAN', CHINESE’, 12984, 23@, ‘2018-05-18 12') conn=sqlite3.connect(‘restaurant.db') cursor=conn.execute("SELECT ID,NANE,CHEF_ID FROM RECIPES where CHEF_ID=520 ") for i in cursor: print(i) (2, "PIzza", 52@) cursor=conn.execute("SELECT DESCRIPTION FROM RECIPES where NAME like 'P%'") for i in cursor: print(i) (‘TTALTAN',) 2) Create a table movie of the below structure and assume data types.Movie_ID, Movie_Name, Genre, Language, Rating ,Do the following queries a. Update the movies rating by 10% and display it. b. Delete the movies with movie_id 102. c. Select movies whose rating is more than 3. import sqlite3 conn = sqlite3.connect(‘restaurant.db') print("Database created successfully") conn.execute('' CREATE TABLE MOVIE1(MOVIE_ID INT NOT NULL,MOVIE_NAME CHAR(42@) NC print("Table created successfully” conn.close() Database created successfully Table created successfully import sqlite conn = sqlite3.connect(‘restaurant.db') conn.execute("" ‘INSERT INTO MOVIE1 VALUES(16@, 'No Time to Die’, ‘Action’, ‘English! conn.execute("’ ‘INSERT INTO MOVIE1 VALUES(162, ‘Annabelle’, ‘Horror’, ‘English’ ,8.0) conn.execute("’ ‘INSERT INTO MOVIE1 VALUES(161, ‘Zindagi na Milegi Dobara’ , ‘Drama’, conn.execute("' ‘INSERT INTO MOVIE1 VALUES(14, ‘Bird Box', ‘Thriller’, ‘English’ ,9.¢ conn.execute("’ ‘INSERT INTO MOVIE1 VALUES(162, ‘Avengers’, ‘Action’, 'English’,9.5)' conn.execute('' ‘INSERT INTO MOVIE1 VALUES(102, ‘Heropanti', "Action’, 'Hindi',7.0)'! conn.conmit() print("Values inserted") conn. close() Values inserted localhost8891inatebookslanacondasiAPP EXPT-S.pyn 2 5115722, 835 PM [APP EXPT-5 - Jupyter Notebook In [15]: conn=sqlite3.connect('restaurant.db") cursor=conn.execute("SELECT * FROM MOVIEI") for i in cursor: print(i) (100, ‘No Time to Die’, ‘Action’, ‘English’, 8.5) (102, ‘Annabelle’, ‘Horror’, ‘English’, 8.0) (101, ‘Zindagi na Milegi Dobara', ‘Drama’, ‘Hindi’, 10.0) (104, ‘Bird Box', ‘Thriller’, ‘English’, 9.0) (102, ‘Avengers’, ‘Action’, ‘English’, 9.5) (102, ‘Heropanti', ‘Action’, ‘Hindi’, 7.6) In [16]: conn.execute('' ‘UPDATE MOVIE1 SET RATING-RATING#(®.1*RATING) '* conn.commit() cursor=conn. execute("SELECT RATING FROM MOVIE1") print("Ratings updated!") for i in cursor: print(4) conn.close() Ratings updated! (9.35,) (8.8,) (11.8,) (9.9,) (10.45, ) (7.74) In [18]: conn=sqlite3.connect('restaurant.db") conn.execute('''DELETE FROM MOVIE1 where MOVIE_ID=1@2''') conn.commit() cursor=conn.execute("SELECT * FROM MOVIEL' print("Records Deleted!") for i in cursor: print(i) Records Deleted! (100, ‘No Time to Die", ‘Action’, ‘English’, 9.35) (101, ‘Zindagi na Milegi Dobara’, ‘Drama’, ‘Hindi’, 11.0) (104, "Bird Box', ‘Thriller’, ‘English’, 9.9) In [19]: conn=sqlite3.connect('restaurant.db') cursor=conn.execute("SELECT MOVIE_NAME RATING FROM MOVIE1 where RATING>3.0") for i in cursor: print(i) conn.close() (‘No Time to Die',) (‘Zindagi na Milegi Dobara’,) (Bird Box',) 3) Create a course database with the following fields Product(ID, Prod_name, localhost 8891inatebookslanacondasiAPP EXPT-S.pyn a7 5115722, 835 PM In [31]: In [32]: In [33]: [APP EXPT-5 - Jupyter Notebook ‘Supplier_id,Unit_price,Package,OrderlD), Orderltem(ID,Order_id,Product_id,Unit_price, play the total quantity of every product in the stock e. Sort the Unit_price based on the supplier_id f. Display the Product_name along with order_id and supy import sqlite3 conn = sqlite3.connect('course.db') print("Database created successfully") #conn.execute("*'CREATE TABLE PRODUCT(PROD_ID INT NOT NULL,PROD_NAME CHAR(400) NC conn.execute('' ‘CREATE TABLE ORDER_ITEM(ORDER_ID INT NOT NULL,PRODUCT_ID INT NOT print("Table created successfully” conn. close() Database created successfully Table created successfully conn=sqlite3.connect('course.db') conn.execute("INSERT INTO PRODUCT VALUES(1, ‘Table’ ,25,500.5,2,200)") conn.execute( "INSERT INTO PRODUCT VALUES(2, "Pen-Stand’ ,34,35.75,4,208)") conn .execute( "INSERT INTO PRODUCT VALUES(3, ‘Water Bottle’, 31,110.0,1,302)") conn. execute(" INTO PRODUCT VALUES(4, ‘Earings' ,12,25.58,7,2@5)") conn. execute(" INTO ORDER_ITEM VALUES(10,1,500.5,1)") conn. execute(" INTO ORDER_ITEM VALUES(11,2,35.75,2)") conn. execute(" INTO ORDER_ITEM VALUES(12,3,110.0,3)") conn. execute(" INTO ORDER_ITEM VALUES(13,4,250.50,4)") print("values inserted") conn. conmit() conn.close() values inserted conn=sqlite3.connect(‘course.db") cursor=conn.execute("SELECT * FROM PRODUCT") for i in cursor: print (i) cursor=conn.execute("SELECT * FROM ORDER_ITEM") for j in cursor: print(j) (1, ‘Table’, 25, 500.5, 2, 200) (2, ‘Pen-Stand', 34, 35.75, 4, 268) (3, ‘Water Bottle’, 31, 110.0, 1, 30@) (4, ‘Earings’, 12, 258.5, 7, 205) (10, 1, 580.5, 1) (11, 2, 35.75, 2) (12, 3, 110.0, 3) (13, 4, 250.5, 4) localhost8891inatebookslanacondasiAPP EXPT-S.pyn an 5115722, 835 PM In [34]: In [37]: In [39]: In [40]: [APP EXPT-5 - Jupyter Notebook conn=sqlite3.connect('course.db") cursor=conn.execute("SELECT QUANTITY FROM ORDER_ITEM") for i in cursor: print(i) (a) (25) (3,) (4) conn=sqlite3.connect( course.db") conn.execute("SELECT * FROM PRODUCT ORDER BY SUPPLIER_ID AS conn.commit() cursor=conn.execute("SELECT PRICE FROM PRODUCT") for i in cursor: print(i) (500.5, ) (35.75,) (110.0,) (258.5,) cursor=conn.execute("SELECT PROD_NAME,ORDER_ID,SUPPLIER_ID FROM PRODUCT") for i in cursor: print(4) conn.close() ('Table’, 200, 25) (’Pen-Stand", 28, 34) (Water Bottle’, 300, 31) (‘Earings’, 205, 12) 4) Write a SQL lite3 statement to create a table named as job including columns job_id,job_title,Minsalary,Max_salary.job_id column does not contain any duplicate value at the time of insertion. conn = sqlite3.connect('job.db') print("Database created successfully") conn.execute("''CREATE TABLE JOB(J0B_ID INT PRIMARY KEY NOT NULL,JOB_TITLE CHAR(] print("Table created successfully” conn. close() Database created successfully Table created successfully localhost8891inatebookslanacondasiAPP EXPT-S.pyn 57 5115722, 835 PM In [42]: In [44]: In [45]: In [50]: [APP EXPT-5 - Jupyter Notebook conn=sqlite3.connect('job.db') conn.execute(''' INSERT INTO JOB VALUES(1@11, ‘Manager 50000, 1¢¢@00)''* ) conn.execute(''' INSERT INTO JOB VALUES(1@12, ‘Supervisor HR Department’, 1000, 120¢ conn.execute(''' INSERT INTO JOB VALUES(1@13, ‘Web Developer’ ,70¢@,10000)''') conn.execute(''' INSERT INTO JOB VALUES(1@14, 'App Developer’ ,8000,12500)''') conn.execute(''' INSERT INTO JOB VALUES(1@15, 'CFO" ,5¢0000, 1000008) ''*) conn..conmit() print("Values inserted with JOB_ID having unique value for each entry.") conn.close() Values inserted with J0B_ID having unique value for each entry. conn=sqlite3.connect(' job.db') cursor=conn.execute("SELECT * FROM 308" for i in cursor: print(i) (1011, ‘Manager’, 5000.0, 100008.0) (1012, ‘Supervisor HR Department’, 10000.@, 12000.6) (1013, ‘Web Developer’, 7000.0, 1000.0) (1014, ‘App Developer’, 8000.0, 1250.0) (1015, ‘CEO’, 500000.0, 1000000.) 5) Write a SQL lite3 statement to create a table names as job_history including columns id, start_date, end_date, job_id and department_id and make sure that, the ‘employee _id column does not contain any duplicate value at the time of insertion and the foreign key column job_id contain only those values which are exists in the jobs table. conn=sqlite3.connect(' job.db") conn.execute('''CREATE TABLE JOB_HISTORV(EMPLOYEE_ID INT PRIMARY KEY,START_DATE C conn.commit() print("Table created!") conn.close() Table created! import sqlite3 conn=sqlite3.connect(’ job.db") conn.execute("INSERT INTO 208_HISTORY VALUES(130, '2002-12-03'" , "2008-04-18" ,1012,¢ conn.execute("INSERT INTO JOB HISTORY VALUES(245, "1995-10-30" , "2004-06-21" ,1013,£ conn.execute("INSERT INTO JOB HISTORY VALUES(135, '2018-07-11" ,'2622-12-31' ,1014,2 conn.execute("INSERT INTO J0B HISTORY VALUES(2@9, "1999-11-95", '210-08-19" ,1011,1 conn.execute("INSERT INTO 30B_HISTORY VALUES(3@0, '2009-@9-17" ,'221-03-@3",1015,: conn..commit() print("Values inserted!") conn. close() Values inserted! localhost8891inatebookslanacondasiAPP EXPT-S.pyn or 5115722, 835 PM [APP EXPT-5 - Jupyter Notebook In [52]: import sqlite} conn=sqlite3.connect(' job.db') cursor=conn.execute("SELECT * FROM JOB_HISTORY") for i in cursor: print(i) (130, '2082-12-03', '2008-04-18', 1012, 450) (245, '1995-16-30", '2004-06-01', 1013, 573) (135, '2018-07-11', '2022-12-31', 1014, 298) (209, '1999-11-@5', '2010-@8-19', 1011, 100) (300, '2089-09-17', '2021-03-03', 1015, 376) RESULT: DECLARATIVE PROGRAMMING PARADIGM USING SQLITE 3 HAS SUCCESSFULLY BEEN EXECUTED localhost8891inatebookslanacondasiAPP EXPT-S.pyn W

You might also like