Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a data table in a database

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report