溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表

發(fā)布時間:2022-04-02 15:24:16 來源:億速云 閱讀:287 作者:iii 欄目:移動開發(fā)

這篇文章主要介紹了數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表文章都會有所收獲,下面我們一起來看看吧。

創(chuàng)建數(shù)據(jù)表

創(chuàng)建數(shù)據(jù)表使用 "CREATE TABLE" 語句,創(chuàng)建數(shù)據(jù)表前,需要確保數(shù)據(jù)庫已存在,以下創(chuàng)建一個名為 sites 的數(shù)據(jù)表:

demo_mysql_test.py:

import mysql.connector 

mydb = mysql.connector.connect(  

host="localhost",  

user="root",  

passwd="123456",  

database="runoob_db"

)

mycursor = mydb.cursor() 

mycursor.execute("CREATE TABLE sites (name VARCHAR(255), url VARCHAR(255))")

執(zhí)行成功后,我們可以看到數(shù)據(jù)庫創(chuàng)建的數(shù)據(jù)表 sites,字段為 name 和 url。

數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表

我們也可以使用 "SHOW TABLES" 語句來查看數(shù)據(jù)表是否已存在:

demo_mysql_test.py:

import mysql.connector 

mydb = mysql.connector.connect(  

host="localhost",  

user="root",  

passwd="123456",  

database="runoob_db"

)

mycursor = mydb.cursor() 

mycursor.execute("SHOW TABLES") 

for x in mycursor:  

print(x)

關(guān)于“數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“數(shù)據(jù)庫中怎么創(chuàng)建數(shù)據(jù)表”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI