Run SQL File: Free Programs to Execute and Query Output

Click For Summary

Discussion Overview

The discussion revolves around executing an SQL file containing commands to generate tables and run queries. Participants explore various free programs and methods to run SQL files, addressing issues related to executing the same file multiple times and the implications of different SQL command types.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Conceptual clarification

Main Points Raised

  • One participant seeks free programs to execute an SQL file and mentions confusion regarding MySQL.
  • Another participant suggests using the MySQL server to run the SQL file and provides a command line example.
  • There are discussions about whether to run the SQL file as a whole or in parts, with some participants suggesting that Microsoft's SQL server could be a solution.
  • Concerns are raised about running the same SQL file multiple times, particularly if it contains Data Definition Language (DDL) commands that could alter the database schema.
  • Some participants explain the differences between SQL command types: DDL, Data Manipulation Language (DML), and Data Control Language (DCL), noting that DML commands can generally be rerun without issue, while DDL commands may cause errors if executed multiple times.
  • There is a discussion about the implications of running SQL files in different virtual machines and the potential for schema conflicts.
  • One participant expresses a desire to improve their questioning skills and acknowledges the learning process through feedback received in the discussion.

Areas of Agreement / Disagreement

Participants express differing views on the implications of running SQL files multiple times, particularly regarding the use of DDL commands. There is no consensus on the best approach to execute the SQL file or the potential issues that may arise from doing so in different environments.

Contextual Notes

Participants highlight the importance of understanding the types of SQL commands being used and their effects on the database. There are indications of varying levels of familiarity with relational databases among participants, which may influence the discussion.

WWGD
Science Advisor
Homework Helper
Messages
7,795
Reaction score
13,095
Hi all,
I have an .sql file; written as a set of commands, as a general text file,
with a .sql extension. I need to execute it in order to get some tables as
output, and then run some queries on these tables.
Are there some free programs to run/execute the file? I got some hits on
a search suggesting some sort of free MySQL file, but I have found nothing.
Thanks for any ideas.
 
Computer science news on Phys.org
the mysql server itself is what runs these files.

mysql -u yourusername -p yourpassword yourschemal < textfile.sql
 
  • Like
Likes   Reactions: WWGD
What have you been using to run the SQL code that you've been studying for the past several weeks?

WWGD said:
So I guess I download Microsoft's SQL server for free

Another option is the MySQL Community server:

http://dev.mysql.com/downloads/mysql/

I use it on Mac OS, and it's very popular on Linux, but I see there's also a Windows installer.
 
Last edited:
  • Like
Likes   Reactions: Silicon Waffle and WWGD
Thank you all, I think I realized where my confusion was; it seems I am having trouble since I have executed (run) the
file as a query (in SQL 2014) more than once. First time is fine, but I seem to be having trouble running the same initial file as a query more than
once.
 
Probably this is because whatever the SQL program does, it is changing the database file/s itself in some way.
It is designed to process an expected set of data and process it, job done.
 
  • Like
Likes   Reactions: Silicon Waffle
Seems to be some assumptions that need a tune-up.
SQL is arbitrarily divided into flavors:
Data definition language DDL - examples CREATE, ALTER, DROP
Data manipulation language DML - examples SELECT UPDATE DELETE INSERT
Data control language DCL - examples GRANT

You can rerun a SQL file DML-only practically forever. Identical file, many times, with some exceptions about data integrity violations.
If you rerun a DML-containing file with commands like CREATE you get errors. ALTER - if it is a different statement each time - is okay.
If you rerun DCL it is usually not going to break stuff, but is a crummy idea except in special cricumstances.

Based on your comment it looks like your SQL has DDL in it. Do not rerun it adhoc like that.
 
Yeah, if you are trying to create something, you need to wrap it in an IF EXISTS, most sql files are not meant to be run more than once.
 
  • #10
jim mcnamara said:
Seems to be some assumptions that need a tune-up.
SQL is arbitrarily divided into flavors:
Data definition language DDL - examples CREATE, ALTER, DROP
Data manipulation language DML - examples SELECT UPDATE DELETE INSERT
Data control language DCL - examples GRANT

You can rerun a SQL file DML-only practically forever. Identical file, many times, with some exceptions about data integrity violations.
If you rerun a DML-containing file with commands like CREATE you get errors. ALTER - if it is a different statement each time - is okay.
If you rerun DCL it is usually not going to break stuff, but is a crummy idea except in special cricumstances.

Based on your comment it looks like your SQL has DDL in it. Do not rerun it adhoc like that.

Thank you. The SQL I am running lives in a virtual machine. Would there be problems running/executing the same file in different VMs?
 
  • #11
The problem is the database content. Re-running DDL can trash an existing schema. Generally you have a single copy of a db on a server. Then you have physically or virtually separate multiple clients running SQL scripts. AFTER the initial DDL run to create the on DB for everybody to use.

Some db's are distributed to local machines after they are built. Code library software uses db technology sometimes. In this case one DB instance per user. But the schema and some seed data exist on the distribution.

There is definitely some sort of disconnect here - could be on my side. If you would, please give us a couple of answers:
1. what is the application requirement the DB meets? (Learn to play DBA, track car repairs, track entries in a collection - are the kind of answer we need here)
2. I gather you understand programming but not relational databases and their real world uses. Correct?
 
  • #12
jim mcnamara said:
The problem is the database content. Re-running DDL can trash an existing schema. Generally you have a single copy of a db on a server. Then you have physically or virtually separate multiple clients running SQL scripts. AFTER the initial DDL run to create the on DB for everybody to use.

Some db's are distributed to local machines after they are built. Code library software uses db technology sometimes. In this case one DB instance per user. But the schema and some seed data exist on the distribution.

There is definitely some sort of disconnect here - could be on my side. If you would, please give us a couple of answers:
1. what is the application requirement the DB meets? (Learn to play DBA, track car repairs, track entries in a collection - are the kind of answer we need here)
2. I gather you understand programming but not relational databases and their real world uses. Correct?

It is more of my having the bad habit of asking simple or poorly-phrased questions and then figuring them out right after I have asked them. I am trying to break it and just think things through carefully and avoid asking poor-quality questions -- thanks for your patience.
 
  • #13
Sorry, I don't mean to belittle the feedback, which has been very helpful, I meant that I do not always stop to think things through as I should.
There is also the fact that even if/when I know or should know the answer, I learn new things from the feedback, and by asking alone and seeing the
answer the material is reinforced and I learn some new things at the same time, and dispel some misconceptions. Thanks to all again.
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 7 ·
Replies
7
Views
5K
Replies
16
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K