generate functionSun, 20 Nov 2022

Define a function to create table of given name.take names of columns,and it's data type, in MySQL using MySQL module

def create_table(name, data_type): db = MySQLdb.connect(host = "localhost", user = "root", password = "password") cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("USE sql_challenges") cursor.execute("DROP TABLE IF EXISTS {0}".format(name)) cursor.execute("CREATE TABLE {0}({1} {2})".format(name, name, data_type)) db.commit() db.close()

Questions about programming?Chat with your personal AI assistant