1

I've been writing SQL in environments where the databases and tables are all easy to pull in using simple 'FROM db.table'. Now I'm trying to do my own project on .csv files. I want to be able to write all of my queries in .sql files and execute them using command line.

I'm uncertain about the following:

  1. What the best program to use is.
  2. Wow to execute a .sql file from command line.
  3. How to import a .csv file.

Yipes! I'm new to using command line and I'm new to pulling in my own tables.

I'm currently trying out SQLlite3, but from the documentation* it doesn't look like I can simply execute a .sql file using SQLlite3 in command line. I've tried running "sqlite3 HelloWorld.sql" in command line for a file that just has "SELECT 'Hello World';" in it and this is what I get:

SQLite version 3.9.2 2015-11-02 18:31:45 Enter ".help" for usage hints. sqlite>

Any advice would be greatly appreciated!

3
  • Try sqlite3 Your.db < HelloWorld.sql Commented Jun 30, 2016 at 19:59
  • I don't currently have a database; only .csv files that I want to import for use. Do I need to create a database and import the .csv files into them first? Commented Jul 6, 2016 at 19:30
  • I couldn't say as I don't have SQLite3 loaded. I just use the DLLs to connect to databases I create in SQLite Browser. I do know that when my .Net code tries to open a database that doesn't exist, it creates a 0 byte file. Give it a shot and see what errors if any you get. Commented Jul 6, 2016 at 19:50

1 Answer 1

0

On Windows you can execute SQL (files) via the command line:

>sqlite3 "" "SELECT 'Hello World!';"
Hello World!

>sqlite3 "" ".read HelloWorld.sql"
Hello World!

This won't create a database file because the first parameter is empty ("") and would normally yield in a database file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.