< 1 min read
You can delete an existing table by using the “DROP TABLE” statement:
Үүсгэгдсэн хүснэгтийг устгахын тулд “DROP TABLE” команд хэрэглэнэ:
Delete the table “customers”:
“customers” хүснэгтийг устгах:
import mysql.connectormydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase")mycursor = mydb.cursor()sql = "DROP TABLE customers"mycursor.execute(sql)
If the table you want to delete is already deleted, or for any other reason does not exist, you can use the IF EXISTS keyword to avoid getting an error.
IF EXISTS
Устгах хүснэгт тань аль хэдийн устгагдсан эсвэл ямар нэгэн шалтгаанаар байхгүй бол IF EXISTS түлхүүр үгийг ашиглан алдаа авахгүй байж болно.
Delete the table “customers” if it exists:
Хэрэв “customers” хүснэгт байгаа бол устгах:
import mysql.connectormydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword", database="mydatabase")mycursor = mydb.cursor()sql = "DROP TABLE IF EXISTS customers"mycursor.execute(sql)
Powered by BetterDocs
You must be logged in to post a comment.