0% found this document useful (0 votes)
2 views8 pages

Python STUB Program

The document provides a series of Python code examples for MySQL database connectivity, including creating databases and tables, inserting records, and fetching data. It includes specific instructions for creating databases named STOCK, LIBRARY, SCHOOL, and BANK, along with corresponding tables and sample data. Each section outlines the SQL commands needed to perform these tasks within a Python script using the MySQLdb library.

Uploaded by

Mehul Srivastava
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)
2 views8 pages

Python STUB Program

The document provides a series of Python code examples for MySQL database connectivity, including creating databases and tables, inserting records, and fetching data. It includes specific instructions for creating databases named STOCK, LIBRARY, SCHOOL, and BANK, along with corresponding tables and sample data. Each section outlines the SQL commands needed to perform these tasks within a Python script using the MySQLdb library.

Uploaded by

Mehul Srivastava
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

QUESTION 1

Keeping in view of My SQL Data Connectivity with Python, fill in the blanks with appropriate SQL
Queries to make the Code work as per the following instructions:

Python code to perform the following tasks:


a. Create a database named STOCK
b. Open the above created database
c. Create a table named ITEMS with attributes as
i. INO of type DECIMAL, Size 5
ii. INAME of type CHAR, Size 20
iii. QUANTITY of type DECIMAL, Size 3
d. Insert 3 records into the table of ITEMS as follows
INO INAME QUANTITY
1 PEN 100
2 PENCIL 150
3 ERASER 200

e. Fetch and display all the records from the table ITEMS

STUB Program
import MySQLdb

db=[Link](host="localhost",user="root",passwd="sql",port=3306)

C=[Link]()
# Create a Database STOCK

[Link]( )

# Open the Database STOCK


[Link]( )

# Create a Table ITEMS


[Link]( )

# Insert 3 rows with above data in Table ITEMS


[Link]( )

[Link]( )

[Link]( )

# Fetch and display all the records from the table ITEMS
[Link]( )
R=[Link]()
for i in R:
print(i)
ANSWER QUESTION.1

import MySQLdb

db=[Link](host="localhost",user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database STOCK


Ans:
[Link]("CREATE DATABASE STOCK")

# Open the Database STOCK


Ans:
[Link]("USE STOCK")

# Create a Table ITEM


Ans:
[Link]("CREATE TABLE ITEMS (INO DECIMAL(5),INAME CHAR(20),QTY DECIMAL(3))")

# Insert 3 rows with above data in Table ITEMS


Ans:
[Link]("INSERT INTO ITEMS VALUES (1,'PEN',100)")

[Link]("INSERT INTO ITEMS VALUES (2,'PENCIL',150)")

[Link]("INSERT INTO ITEMS VALUES (3,'ERASER',200)")

[Link]()

# Fetch and display all the records from the table ITEMS
Ans:
[Link]("SELECT * FROM ITEMS")

R=[Link]()
for i in R:
print(i)
QUESTION 2
Keeping in view of My SQL Data Connectivity with Python, fill in the blanks with appropriate SQL
Queries to make the Code work as per the following instructions:

Write missingPython code to perform the following tasks:


[Link] a database named LIBRARY
[Link] the above created database
[Link] a table named BOOKS with attributes as
i. BNO of type CHAR, size 10
ii. BNAME of type CHAR, size 20
iii. PRICE of type DECIMAL, size 8 with 2 decimal places
d. Insert 3 records into the table of BOOKS as follows
BNO BNAME PRICE
1 MY ADVENTURES 120
2 A TRUE LIE 250
3 JUSTICE DONE 320

e. Fetch and display all the records from the table BOOKS

STUB Program
import MySQLdb

db=[Link](host="localhost",user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database LIBRARY


[Link]( )

# Open the Database LIBRARY


[Link]( )

# Create a Table BOOKS


[Link]( )

# Insert 3 rows with above data in Table BOOKS


[Link]( )

[Link]( )

[Link]( )

# Fetch and display all the records from the table BOOKS
[Link]( )

R=[Link]()
for b in R:
print(b)
ANSWER QUESTION.2

import MySQLdb

db=[Link](host="localhost",user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database LIBRARY


Ans:
[Link]("CREATE DATABASE LIBRARY")

# Open the Database LIBRARY


Ans:
[Link]("USE LIBRARY")

# Create a Table BOOKS


Ans:
[Link]("CREATE TABLE BOOKS (BNO CHAR(10),INAME CHAR(20),PRICE
DECIMAL(8,2))")

# Insert 3 rows with above data in Table BOOKS


Ans:
[Link]("INSERT INTO BOOKS VALUES ('1','MY ADVENTURE',120)")

[Link]("INSERT INTO BOOKS VALUES ('2','A TRUE LIE',250)")

[Link]("INSERT INTO BOOKS VALUES ('3','JUSTICE DONE',320)")

[Link]()

# Fetch and display all the records from the table BOOKS
Ans:
[Link]("SELECT * FROM BOOKS")

R=[Link]()
for i in R:
print(i)
QUESTION 3
Keeping in view of My SQL Data Connectivity with Python, fill in the blanks with appropriate SQL
Queries to make the Code work as per the following instructions:

Write missingPython code to perform the following tasks:


[Link] a database named SCHOOL
[Link] the above created database
[Link] a table named RESULT with attributes as
i. ADNO of type CHAR, size 10
ii. SNAME of type CHAR, size 20
iii. AGG of type DECIMAL, size 8 with 2 decimal places
d. Insert 3 records into the table of RESULT as follows
ADNO SNAME AGG
R001 JASVEER 98
R002 SONAKSHI 85
R003 ANANYA 92

e. Fetch and display all the records from the table RESULT

STUB Program
import MySQLdb

db=[Link](host="localhost",
user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database SCHOOL


[Link]( )

# Open the Database SCHOOL


[Link]( )

# Create a Table RESULT


[Link]( )

# Insert 3 rows with above data in Table RESULT


[Link]( )

[Link]( )

[Link]( )

# Fetch and display all the records from the table RESULT
[Link]( )

R=[Link]()
for b in R:
print(b)
ANSWER QUESTION.3

import MySQLdb

db=[Link](host="localhost",
user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database LIBRARY


Ans:
[Link]("CREATE DATABASE SCHOOL")

# Open the Database SCHOOL


Ans:
[Link]("USE SCHOOL")

# Create a Table RESULT


Ans:
[Link]("CREATE TABLE RESULT (ADNO CHAR(10),SNAME CHAR(20),AGG
DECIMAL(8,2))")

# Insert 3 rows with above data in Table RESULT


Ans:
[Link]("INSERT INTO RESULT VALUES ('R001','JASVEER',98)")

[Link]("INSERT INTO RESULT VALUES ('R002','SONAKSHI',85)")

[Link]("INSERT INTO RESULT VALUES ('R003','ANANYA',92)")

[Link]()

# Fetch and display all the records from the table RESULT
Ans:
[Link]("SELECT * FROM RESULT")

R=[Link]()
for i in R:
print(i)
QUESTION 4
Keeping in view of My SQL Data Connectivity with Python, fill in the blanks with appropriate SQL
Queries to make the Code work as per the following instructions:

Write missingPython code to perform the following tasks:


[Link] a database named BANK
[Link] the above created database
[Link] a table named CUSTOMER with attributes as
i. ANO of type CHAR, size 10
ii. CNAME of type CHAR, size 20
iii. BALANCE of type DECIMAL, size 8 with 2 decimal places
d. Insert 3 records into the table of CUSTOMER as follows
ANO CNAME BALANCE
01234 ARIYA 965000.67
01567 SIMAR 1087000.45
03476 JEFFY 2456000.23

e. Fetch and display all the records from the table CUSTOMER

STUB Program
import MySQLdb

db=[Link](host="localhost",
user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database BANK


[Link]( )

# Open the Database BANK


[Link]( )

# Create a Table CUSTOMER


[Link](_________________________________________________)

# Insert 3 rows with above data in Table CUSTOMER


[Link]( )

[Link]( )

[Link]( )

# Fetch and display all the records from the table CUSTOMER
[Link]( )

R=[Link]()
for b in R:
print(b)
ANSWER QUESTION.4

import MySQLdb

db=[Link](host="localhost",
user="root",passwd="sql",port=3306)
C=[Link]()

# Create a Database BANK


Ans:
[Link]("CREATE DATABASE BANK")

# Open the Database BANK


Ans:
[Link]("USE BANK")

# Create a Table CUSTOMER


Ans:
[Link]("CREATE TABLE CUSTOMER (ANO CHAR(10),CNAME CHAR(20),BALANCE
DECIMAL(8,2))")

# Insert 3 rows with above data in Table CUSTOMER


Ans:
[Link]("INSERT INTO CUSTOMER VALUES ('01234','ARIYA',965000.67)")

[Link]("INSERT INTO CUSTOMER VALUES ('01567','SIMAR',1087000.45)")

[Link]("INSERT INTO CUSTOMER VALUES ('03476','JEFFY',2456000.23)")

[Link]()

# Fetch and display all the records from the table CUSTOMER
Ans:
[Link]("SELECT * FROM CUSTOMER")

R=[Link]()
for c in R:
print(c)

You might also like