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

 

549 people joined Teachoo Black. What are you waiting for?

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.