Check sibling questions
Computer Science - Class 12
Chapter 15 - Interface of Python with SQL Database

Write Python code to create a table Faculty with following fields.

Id, LastName, FirstName, LocationId, phone, rank, startdate

Rank should be one of the following

ASSO, FULL, ASST, INST

 

Answer:

 

import mysql.connector.connect

db=mysql.connector.connect('localhost','root','root','College')

cursor=db.cursor()

sql="create table Faculty(Id int,LastName varchar(15),FirstName

varchar(15),LocationId int,phone int,rank varchar(4) check(rank

IN('ASSO','FULL','ASST','INST')),startdate date)"

try:

cursor.execute(sql)

db.commit()

except:

db.rollback()

db.close()

 

Davneet Singh's photo - Teacher, Engineer, Marketer

Made by

Davneet Singh

Davneet Singh is a graduate from Indian Institute of Technology, Kanpur. He has been teaching from the past 12 years. He provides courses for Maths and Science at Teachoo.