mysql创建表sql_MySQL教程:创建SQL表

mysql创建表sql

One of the easiest ways to create a table is through phpMyAdmin, which is available on most hosts that offer MySQL databases (ask your host for a link). First, you need to login to phpMyAdmin.

创建表的最简单方法之一是通过phpMyAdmin,它在提供MySQL数据库的大多数主机上都可用(向主机询问链接)。 首先,您需要登录到phpMyAdmin。

在phpMyAdmin中创建表 ( Create Tables in phpMyAdmin )

Create a table in phpMyAdmin

On the left hand side you will see "phpMyAdmin" logo, some small icons, and below them you will see your database name. Click on your database name. Now on the right hand side any tables you may have in your database will be displayed, as well as a box labeled "Create new table on database"

在左侧,您将看到“ phpMyAdmin”徽标,一些小图标,在它们下方,您将看到您的数据库名称。 单击您的数据库名称。 现在,将在右侧显示数据库中可能包含的所有表,以及一个标有“在数据库上创建新表”的框。

Click this and create a database as we have in the diagram below.

单击此按钮,然后创建数据库,如下图所示。

添加行和列 ( Adding Rows and Columns )

Creating database fields

Let's say we work in a doctor's office and wanted to make a simple table with a person's name, age, height, and the date we collected this information. On the previous page we entered "people" as the name of our table, and chose to have 4 fields. This brings up a new phpmyadmin page where we can fill in the fields and their types to add rows and columns. (See an example above)

假设我们在医生办公室工作,并希望制作一张简单的表格,上面附上一个人的姓名,年龄,身高以及收集这些信息的日期。 在上一页中,我们输入“ people”作为表名,并选择具有4个字段。 这将打开一个新的phpmyadmin页面,我们可以在其中填写字段及其类型以添加​​行和 。 (请参见上面的示例)

We have filled in the field names as: name, age, height, and date. We have set the data types as VARCAR, INT (INTEGER), FLOAT and DATETIME. We set a length of 30 on the name, and have left all other fields blank.

我们将字段名称填写为:名称,年龄,身高和日期。 我们将数据类型设置为VARCAR,INT(INTEGER),FLOAT和DATETIME。 我们将名称的长度设置为30,并将所有其他字段留空。

phpMyAdmin中SQL查询窗口 ( SQL Query Window in phpMyAdmin )

Perhaps a quicker way to add a table is by clicking on the small "SQL" button on the left hand side below the phpMyAdmin logo. This will bring up a query window where we can type our commands. You should run this command:

也许添加表的更快方法是单击phpMyAdmin徽标下方左侧的小“ SQL”按钮。 这将打开一个查询窗口,我们可以在其中键入命令。 您应该运行以下命令:

As you can see, the command "CREATE TABLE" does exactly that, creates a table which we have called "people". Then inside the ( brackets ) we tell it what columns to make. The first is called "name" and is VARCAR, the 30 indicates we are allowing up to 30 characters. The second, "age" is an INTEGER, the third "height" is a FLOAT and the forth "date" is DATETIME.

如您所见,命令“ CREATE TABLE”正是这样做的,创建了一个我们称为“ people”的表。 然后在(方括号)内告诉它要制作什么列。 第一个称为“名称”,即VARCAR,30表示我们允许最多30个字符。 第二个“年龄”是一个整数,第三个“高度”是一个浮点数,第四个“日期”是DATETIME。

Regardless of which method you chose, if you would like to see a breakdown of what you just did click on the "people" link that now appears on the left hand side of your screen. On the right you should now see the fields you added, their data types, and other information.

无论您选择哪种方法,如果您想查看一下您所做的细目分类,请单击屏幕左侧现在显示的“人员”链接。 现在,您应该在右侧看到添加的字段,它们的数据类型和其他信息。

使用命令行 ( Using Command Lines )

If you prefer you can also run commands from a command line to create a table. A lot of web hosts don't give you shell access to the server anymore, or allow remote access to the MySQL servers. If you want to do it this way you may have to install MySQL locally, or try this nifty web interface. First you will need to login to your MySQL database. If you are unsure how try using this line: mysql -u Username -p Password DbName Then you can run the command:

如果愿意,还可以从命令行运行命令以创建表。 许多Web主机不再为您提供Shell访问服务器的权限,也不再允许您远程访问MySQL服务器。 如果您想以这种方式进行操作,则可能必须在本地安装MySQL,或尝试使用此漂亮的Web界面。 首先,您需要登录到您MySQL数据库。 如果不确定如何尝试使用此行: mysql -u用户名-p密码DbName然后可以运行以下命令:

To view what you have just created try typing in:

要查看您刚刚创建的内容,请尝试输入:

describe people;

描述

No matter which method you chose to use, you should now have a table setup and ready for us to enter data into.

无论您选择使用哪种方法,现在都应该有一个表格设置,可以让我们将数据输入其中。

翻译自: https://www.thoughtco.com/mysql-tutorial-create-sql-tables-2693877

mysql创建表sql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值