This article brings you an introduction to the method of creating a data table in Mysql (with examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The data table is one of the most important components of the database and is the basis for other objects. If our database does not have a data table, it means that there is no real place to store data (recommended course: MySQL Tutorial)
Open the database
We log in After mysql open the database we want to open.
We open the database named test, command: USE test
After opening the database, we To create a data table, let’s first understand the command rules for creating a data table
CREATE TABLE [IF NOT EXISTS] table_name( column_name data_type, column_name data_type, ... )
Parameter description
column_name | Column name |
data_type | Data type |
Let’s create a basic data Table, username, age, password, salary
CREATE TABLE ta1( usename VARCHAR(20), age TINYINT UNSIGNED, passwrod VARCHAR(16), gz FLOAT(8,2) UNSIGNED )
In the above command, we declare a data table named ta1. The data table has 4 fields.
The usename field is a user name from 1 to 20 characters
age field is a number from 0 to 255, UNSIGINED is expressed as an unsigned type
The passwrod field is a password from 1 to 16 characters
gz field It is 8 digits, with 2 decimal places. UNSIGINED is expressed as an unsigned type
Command rules
SHOW TABLES [FROM ab_name] [LINK 'pattern' | WHERE expr ]
Enter the command to view the data table:
SHOW TABLES;
Command rules for viewing the data structure:
SHOW COLUMNS FROM table_Name;
Enter the command to view the data structure
SHOW COLUMNS FROM user;
We can see The data structure is exactly the same as what was specified when creating it.
The above is the detailed content of Introduction to the method of creating data tables in Mysql (with examples). For more information, please follow other related articles on the PHP Chinese website!