0

For my database class the teacher assigned us to use Oracle SQL to design an application. Because I have more experience with mySQL he said I could use it instead.

I want to make my assignment look as simliar to his example as possible. What his example consists of of is one file run.sql that looks like this:

@start //this runs start.sql which creates the tables

DESC table_name; //do this for all tables

@insert //this runs insert.sql that creates dummy data

SELECT * FROM table_name; //do this for all tables

@query //this runs query.sql that runs our sample queries

@drop //this kills all the data

Is there a way to do something simliar?

Namely a way to write a query that calls external queries and outputs all data to an output.txt file?

0

2 Answers 2

1

Use 'source' to input the *.sql files

use 'create procedure' to generate the 'drop' function

use "into outfile '/file/path';" on your select to write out.

double redirect to append: "into outfile '>>/file/path';"

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

2 Comments

Is there a way to do something like this? SOURCE run.sql INTO OUTFILE 'output.txt';
I found this works: mysql -p dbname < foo.sql > foo.txt but doesn't contain all output or pretty print.
0

The source command for the mysql command-line client could do the job here:

source start.sql;

DESC table_name;

You can get more commands with help.

2 Comments

that worked! now just to figure out how to get it to print output
It should display the output of any queries it runs by default. If you need formatting, looks like @ChrisSM has you covered.

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.