Python MySQL ਤੇਬਲ ਹਟਾਓ
- ਪਿਛਲਾ ਪੰਨਾ MySQL ਹਟਾਓ
- ਅਗਲਾ ਪੰਨਾ MySQL ਅੱਪਡੇਟ
ਤੇਬਲ ਹਟਾਓ
ਤੁਸੀਂ "DROP TABLE" ਸਟੇਟਮੈਂਟ ਦੀ ਵਰਤੋਂ ਕਰ ਸਕਦੇ ਹੋ ਕੇ ਮੌਜੂਦ ਤੇਬਲ ਹਟਾ ਸਕਦੇ ਹੋ:
ਉਦਾਹਰਣ
ਹਟਾਓ "customers" ਤੇਬਲ:
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", passwd="yourpassword", database="mydatabase" ) mycursor = mydb.cursor() sql = "DROP TABLE customers" mycursor.execute(sql)
ਸਿਰਫ ਤੇਬਲ ਮੌਜੂਦ ਹੋਣ ਤੇ ਹਟਾਓ
ਜੇਕਰ ਹਟਾਉਣ ਵਾਲਾ ਤੇਬਲ ਹਟਾਇਆ ਗਿਆ ਹੈ ਜਾਂ ਕਿਸੇ ਹੋਰ ਕਾਰਨ ਨਾਲ ਮੌਜੂਦ ਨਹੀਂ ਹੈ, ਤਾਂ IF EXISTS ਕੀਵਰਡ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਗਲਤੀ ਰੋਕੋ ਹੈ。
ਉਦਾਹਰਣ
ਹਟਾਓ "customers" ਤੇਬਲ (ਜੇਕਰ ਮੌਜੂਦ ਹੈ):
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", passwd="yourpassword", database="mydatabase" ) mycursor = mydb.cursor() sql = "DROP TABLE IF EXISTS customers" mycursor.execute(sql)
- ਪਿਛਲਾ ਪੰਨਾ MySQL ਹਟਾਓ
- ਅਗਲਾ ਪੰਨਾ MySQL ਅੱਪਡੇਟ