What is the relationship between tables and databases

青灯夜游
Release: 2023-01-06 11:18:13
Original
20397 people have browsed it

The relationship between tables and databases is: a database can contain multiple tables. A table (TABLE) is an object used to store data in a database. It is a collection of structured data and is the basis of the entire database system. Each database is composed of several data tables; in other words, there is no data table without a data table. Unable to store data in database.

What is the relationship between tables and databases

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

Table (TABLE) is an object used to store data in a database. It is a collection of structured data and is the foundation of the entire database system. Tables are database objects that contain all the data in a database.

Data tables are an important part of the database. Each database is composed of several data tables. In other words, data cannot be stored in a database without data tables.

For example, create an empty folder on your computer. If you want to store "Hello C Language Chinese Network" in the folder, you must write it in a Word document, Notepad or other document that can store text. middle. The empty folder here is equivalent to the database, and the document storing text is equivalent to the data table.

A table is defined as a collection of columns. Similar to a spreadsheet, data is organized in a table format in rows and columns. Each column in a table is designed to store some type of information (such as a date, name, dollar amount, or number). There are several controls on tables (constraints, rules, default values, and custom user data types) to ensure data validity.

MySQL creates a data table (CREATE TABLE statement)

After creating the database, the next step is to create a data table in the database. The so-called creating a data table refers to creating a new table in the already created database.

The process of creating a data table is the process of specifying the attributes of the data columns, and it is also the process of implementing data integrity (including entity integrity, referential integrity and domain integrity) constraints.

Basic syntax

In MySQL, you can use the CREATE TABLE statement to create a table. The syntax format is:

CREATE TABLE <表名> ([表定义选项])[表选项][分区选项];
Copy after login

Among them, the format of [Table Definition Options] is:

<列名1> <类型1> [,…] <列名n> <类型n>
Copy after login

The CREATE TABLE command syntax is more, which mainly consists of table creation definition (create-definition), Composed of table options (table-options) and partition options (partition-options).

Here we first describe a simple example of creating a new table, and then focus on some main syntax knowledge points in the CREATE TABLE command.

The main syntax and usage instructions of the CREATE TABLE statement are as follows: