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()

 

Get Real time Doubt solving from 8pm to 12 am!

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 12 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.