How to Run an SQL Database Query


The SQL open standard for database query languages provides an interactive shell for typing queries to the database directly. It can also be used to load a text file with a set of queries to the database. The combination of the two methods allows for quick and dirty queries, with a little trial and error to get the right results, followed by saving useful queries for later operations.

  • Log into your database interface; on a Windows machine, this means authenticating your user account to the SQL server. On a UNIX SQL implementation, like MySQL, this means logging into the command line interface, and then typing "mysql database_name." In either case, you'll be logged into the interactive SQL parser tool.

  • Type in the following command to run a database query:

    SELECT '<query_ operation>' AS ' ';

    Replace <query_operation> with your desired query.

  • Type in the following command to have the SQL database run queries contained in a text file:

    mysql database_name < file_name

    where the database_name and file_name parameters are replaced with the name of the actual database and file name to be loaded.

  • Type in the following command to have the SQL database run queries from a text file and output the results to a different text file:

    mysql database_name < file_name > output_file.txt

Tips & Warnings

  • If you do not know what you are doing, you can actually do harm to your database with an SQL database query. If you are unsure, it is always a good idea to make a backup copy of the database before running your queries.

Related Searches


Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!