취미와 밥줄사이
[Python] MySQL Drop Table 본문
테이블 삭제
- "DROP TABLE"문을 사용하여 존재하는 테이블 삭제할 수 있다.
-
# Delete the table "customers" import mysql.connector mydb = mysql.connector.connect( host="localhost", user="your username", password="your password", database="mydatabase" ) mycursor = mydb.cursor() sql = "DROP TABLE customers" mycursor.execute(sql)
테이블이 존재하는 경우에만 삭제
- 삭제하려는 테이블이 이미 삭제되었거나 다른 이유로 존재하지 않는 경우 IF EXISTS 키워드를 사용하여 오류가 발생하지 않도록 할 수 있습니다.
-
# Delte the table "customers" if it exists import mysql.connector mydb = mysql.connector.connect( host="localhost", user="your username", password="your password", database="mydatabase" ) mycursor = mydb.cursor() sql = "DROP TABLE IF EXISTS customers" mycursor.execute(sql)
REFERENCE
https://www.w3schools.com/python/python_mysql_drop_table.asp
Python MySQL Drop Table
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
'DB' 카테고리의 다른 글
[Python] MySQL Limit (0) | 2021.10.28 |
---|---|
[Python] MySQL Update Table (0) | 2021.10.28 |
[Python] MySQL Delete From By (0) | 2021.10.28 |
[Python] MySQL Order By (0) | 2021.10.28 |
[Python] MySQL Where절 사용하기 (0) | 2021.10.28 |