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

Consider the structure of table Doctor given

below

Doctor

Doctor_id(p)

Doctor_Name

Hospital_id(F)

Joining_Date

Speciality

Salary Experience.

Write Python code to create the above table.

 

Answer:

 

import mysql.connector

mydb=mysql.connector.connect("localhost","root","root","Hospital")

cursor=mydb.cursor()

sql="create table Doctor(Doctor_id int primary key,Doctor_Name

varchar(20),Hospital_id int foreign key,Joining_dat date,Speciality

varchar(45),Salary int,Experience int)"

cursor.execute(sql)

cursor.close()

mydb.close()

 

Learn Intergation from Davneet Sir - Live lectures starting soon!

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.