学习SQL硬的方式 - 在SQL Lite中使用.db创建.sql 3 - 为什么和如何? [英] Learn SQL The Hard way - Creating .sql with .db in SQL Lite 3 - Why and How?

查看:132
本文介绍了学习SQL硬的方式 - 在SQL Lite中使用.db创建.sql 3 - 为什么和如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个初始的程序员,+20小时的Python编码和新手熟悉命令行,我打开了Zed Shaw的学习SQL的硬路,很快被困扰。

As a beginning programmer with +20 hours of Python coding and novice familiarity with the command-line, I opened up Zed Shaw's "Learn SQL The Hard Way" and was quickly stumped.

练习01 中,Zed使用此第一个命令创建了第一个表:

In exercise 01, Zed has you create your first table with this first command:

sqlite3 ex1.db < ex1.sql

但是,这无法在我的命令行中运行,提供错误消息 bash:ex1.sql:没有这样的文件或目录。最初,我忽略了这个建议的代码,然后继续:

However this fails to run in my command-line, giving the error message, "-bash: ex1.sql: No such file or directory." Initially, I ignored this recommended code and proceeded with:

sqlite3 ex1.db
SQLite version 3.7.15.1 2012-12-19 20:39:10
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE person (
   ...>     id INTEGER PRIMARY KEY,
   ...>     first_name TEXT,
   ...>     last_name TEXT,
   ...>     age INTEGER
   ...> );

在命令行中运行ls -l显示:

Running "ls -l" in the command-line shows:

-rw-r--r--  1 thefifth  staff  2048 Feb 15 15:23 ex1.db

但是我想要的却不能得到的是:

But what I want and am failing to get is:

$ ls -l
-rw-r--r--  1 zedshaw  staff  2048 Nov  8 16:18 ex1.db
-rw-r--r--  1 zedshaw  staff    92 Nov  8 16:14 ex1.sql

我Googled找到此博客实现了相同的name.db< name.sql语法,但是沿着这里的代码没有工作对我来说。此 Stack Overflow 也有类似的语法,但在转换的上下文中。 sql到sqlite3。

I Googled around and found this blog that implements the same "name.db < name.sql" syntax, but following along the code here didn't work for me either. This Stack Overflow also has a similar syntax, but in the context of converting .sql to sqlite3.

具体来说,我想知道这是否是<在本地bash终端中使用,并且我没有达到其正确使用的某些标准。此外,我不知道创建.sql和.db文件的目的,虽然显然一个比另一个小得多。可能我安装的sqlite3不正确,但它似乎工作正常。

Specifically, I'm wondering if this is the "<" for use in the native bash terminal, and that I'm failing to meet certain criteria for its correct use. Also, I don't know the purpose of creating both a .sql and .db file, although apparently one is much smaller than the other. Perhaps I've installed sqlite3 incorrectly, but it seems to be working fine.

感谢您的帮助!

推荐答案


  1. 将您的代码保存在扩展名为.sql的文件中

  2. 然后在终端:sqlite3 ex1.db< ; ex1.sql用于创建ex1.db

  3. 在终端中输入:sqlite3 ex1.db .schema

  4. 或输入:sqlite3 ex1.db [ ...然后....] .schema

  1. Save your code in a file with the extension .sql
  2. Then in the terminal: sqlite3 ex1.db < ex1.sql for create a ex1.db
  3. Put in the terminal: sqlite3 ex1.db .schema
  4. Or put: sqlite3 ex1.db [... and then....] .schema

这篇关于学习SQL硬的方式 - 在SQL Lite中使用.db创建.sql 3 - 为什么和如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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