Advertisements
Advertisements
Question
Write a Python script to create a table called ITEM with the following specifications.
Add one record to the table.
Name of the database:- ABC
Name of the table:- Item
Column name and specification:-
| Icode | :- | integer and act as primary key |
| Item Name | :- | The character with a length of 25 |
| Rate | :- | Integer |
| Record to be added | :- | 1008, Monitor, 15000 |
Advertisements
Solution
Coding:
import sqlite3
connection = sqlite3 . connect (“ABC.db”)
cursor = connection, cursor ()
sql_command = ” ” ”
CREATE TABLE Item (Icode INTEGER,
Item_Name VARCHAR (25),
Rate Integer); ” ‘” ”
cursor, execute (sql_command)
sql_command = ” ” “INSERT INTO Item
(Icode,Item_name, Rate)VALUES (1008,
“Monitor”, “15000”);” ” ”
cursor, execute (sqlcmd)
connection, commit ()
print(“Table Created”)
cursor. execute(SELECT *FROM ITEM”)
result=cursor.fetchall():
print(“CONTENT OF THE TABLE
print(*result,sep=”\n”)
connection, close ()
Output:
Table Created
CONTENT OF THE TABLE :
(1008, ‘Monitor’, 15000)
