Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create a data table in a database

Shulou Source: shulou.com Published: 2022-06-01 01:33:20 09月21日 Update

This article mainly introduces the relevant knowledge of how to create a data table in the database, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to create a data table in this database. Let's take a look.

Create a datasheet

Use the "CREATE TABLE" statement to create a data table. Before creating a data table, you need to make sure that the database already exists. Create a data table named sites below:

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)")

After successful execution, we can see the data table sites created by the database with fields name and url.

We can also use the "SHOW TABLES" statement to see if the data table already exists:

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)

This is the end of the article on "how to create data tables in the database". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to create data tables in the database". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Data datasheet database knowledge content articles sentences success value fields easy to operate articles easy to understand more read industry information channels channels learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia OPPO Reno Xiaomi vpn