创建表语法_创建表

创建表语法

Now that we know about data types from the previous blog, let’s go over using that to create tables. Once in a while, either when we’re creating a new database or updating one, we may want to create a table to hold new data. Luckily, the basic syntax to create a table in MySQL isn’t too hard.

现在,我们已经从上一篇博客中了解了数据类型,接下来让我们使用它来创建表。 有时,在创建新数据库或更新数据库时,我们可能希望创建一个表来保存新数据。 幸运的是,在MySQL中创建表的基本语法并不难。

创建表 (Creating The Table)

The syntax starts with the CREATE TABLE keywords, followed by a unique table name and then the column names and constraints in parentheses:

语法以CREATE TABLE关键字开头,后跟唯一的表名,然后是括号中的列名和约束:

Image for post

If we were to get specific, a column definition looks like the following, where the keywords in brackets are optional:

如果要具体说明,则列定义如下所示,其中括号中的关键字是可选的:

Image for post

Column constraints can be a restriction such as UNIQUE so that values in a column are all different from each other.

列约束可以是诸如UNIQUE之类的约束,以使列中的值互不相同。

插入值 (Inserting Values)

Once we’ve created he table layout, we should also know how to insert values into them. The syntax for this is shown below:

一旦创建了表布局,我们还应该知道如何在其中插入值。 语法如下所示:

Image for post

This inserts a value of val1 under the first column (col1), and val2 under the second column (col2), and so on. Although this adds only one row, we can add more than one row by separating each row with a comma and enclosing each row with parentheses:

这将在第一列(col1)下插入值val1,在第二列(col2)下插入值val2,依此类推。 尽管这仅增加了一行,但我们可以通过用逗号分隔每行并用括号将每行括起来来添加多行:

Image for post

创建样本表 (Creating a Sample Table)

Now let’s try to create a sample table called STUDENTS that looks like one we’ve seen before:

现在,让我们尝试创建一个名为STUDENTS的示例表,该表看起来像我们之前看到的那样:

Image for post

The column names are ID, Name, and Marks with data types of INT, STRING, and INT respectively. And the values are (1, Ashley, 81), (2, Samantha, 75), (4, Julia, 76), and (3, Belvet, 84).

列名称分别是ID,名称和标记,其数据类型分别为INT,STRING和INT。 值分别是(1,Ashley,81),(2,Samantha,75),(4,Julia,76)和(3,Belvet,84)。

First we’ll set up the table using what we know:

首先,我们将使用已知的信息来设置表格:

Image for post

This will designate what data types can be input into the table for each column. We then need to insert the values as we were told:

这将指定可以为表的每一列输入哪些数据类型。 然后,我们需要按照提示插入值:

Image for post

And there you have it! We’ve created a table and inserted values into it!

在那里,您拥有了! 我们已经创建了一个表并将值插入其中!

翻译自: https://medium.com/@gl7526/creating-tables-307727a06f27

创建表语法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值