我有一个包含很多列的数据集,我想将其导入 MySQL 数据库,因此我希望能够在不手动指定列标题的情况下创建表。相反,我想向(大概)MySQL CREATE TABLE 命令提供一个带有列标签的文件名。我在 Ubuntu 中使用标准 MySQL 查询浏览器工具,但我没有在创建表对话框中看到此选项,也无法弄清楚如何从 CREATE TABLE 文档页面编写查询来执行此操作。但一定有办法...
I have a dataset with a lot of columns I want to import into a MySQL database, so I want to be able to create tables without specifying the column headers by hand. Rather I want to supply a filename with the column labels in it to (presumably) the MySQL CREATE TABLE command. I'm using standard MySQL Query Browser tools in Ubuntu, but I didn't see in option for this in the create table dialog, nor could I figure out how to write a query to do this from the CREATE TABLE documentation page. But there must be a way...
发布评论
评论(1)
CREATE TABLE 语句不仅仅包括列名
* 强制
您无法仅从列名称列表中获得所有这些。您应该自己编写 CREATE TABLE 语句。
回复您的评论:许多软件开发框架支持在不使用 SQL DDL 的情况下声明表的方法。例如 Hibernate 使用 XML 文件。 YAML 受 Rails ActiveRecord、PHP Doctrine 和 Perl 的 SQLFairy 支持。可能还有其他工具使用其他格式(例如 JSON),但我一时不知道。
但最终,所有这些“简化”的接口学习起来并不比 SQL 简单,但无法准确表示 SQL 的作用。另请参阅泄漏抽象定律。
请查看 SQLFairy,因为该工具可能已经以可以帮助您的方式从文件转换为 SQL。 FWIW MySQL Query Browser(或当前名称 MySQL Workbench)可以读取 SQL 文件。所以你可能不必复制 &手动粘贴。
A CREATE TABLE statement includes more than just column names
* mandatory
You can't get all this just from a list of column names. You should write the CREATE TABLE statement yourself.
Re your comment: Many software development frameworks support ways to declare tables without using SQL DDL. E.g. Hibernate uses XML files. YAML is supported by Rails ActiveRecord, PHP Doctrine and Perl's SQLFairy. There are probably other tools that use other format such as JSON, but I don't know one offhand.
But eventually, all these "simplified" interfaces are no less complex to learn as SQL, while failing to represent exactly what SQL does. See also The Law of Leaky Abstractions.
Check out SQLFairy, because that tool might already convert from files to SQL in a way that can help you. And FWIW MySQL Query Browser (or under its current name, MySQL Workbench) can read SQL files. So you probably don't have to copy & paste manually.