How to write SQL statements to create a table in MySQL?
To create a table, you need to use the CREATE TABLE statement in MySQL. Here is an example:
CREATE TABLE 表名 (
列1 数据类型,
列2 数据类型,
列3 数据类型,
...
);
This is the basic structure of a CREATE TABLE statement. You need to replace “table name” with the actual name of the table you want to create, and list the columns of the table along with their corresponding data types in parentheses.
For example, if you want to create a table named “users” with three columns “ID”, “Name”, and “Age”, you can use the following statement:
CREATE TABLE users (
ID INT,
姓名 VARCHAR(50),
年龄 INT
);
In this example, the data type of the ID column is INT (integer), the data type of the Name column is VARCHAR(50) (a string with a maximum length of 50), and the data type of the Age column is INT.
Of course, you can also use more options to define the structure of the table, such as defining primary keys, foreign keys, unique constraints, etc. These options can be customized based on your needs.