SQLite - 从文件运行多行 SQL 脚本? [英] SQLite - Run multi-line SQL script from file?

查看:60
本文介绍了SQLite - 从文件运行多行 SQL 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件 user.sql 中有以下 SQL:

I have the following SQL in a file, user.sql:

CREATE TABLE user
(
  user_id INTEGER PRIMARY KEY,
  username varchar(255),
  password varchar(255)
);

但是,当执行以下命令时:

However, when the following command is executed:

sqlite3 my.db < user.sql 

产生以下错误:

Error: near line 1: near ")": syntax error

我更愿意保持 SQL 原样,因为该文件将被检入源代码管理,并且像现在一样更易于维护和可读.SQL 可以像这样跨越多行,还是我需要把它都放在同一行上?

I would prefer to keep the SQL as-is, as the file will be checked into source control and will be more maintainable and readable as it is now. Can the SQL span multiple lines like this, or do I need to put it all on the same line?

推荐答案

我遇到了完全相同的问题.

I had exactly the same problem.

然后我注意到,我的编辑器 (Notepad++) 报告了 Macintosh 格式的行尾.

Then I noticed, my editor (Notepad++) reports Macintosh format for end of lines.

将eols转换成Unix风格,就是把脚本文件变成sqlite3可以理解的格式.

Converting eols into Unix style turned the script file into format, which sqlite3 understood.

这篇关于SQLite - 从文件运行多行 SQL 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆