SQL Scripting Tutorial


SQL (Structured Query Language) is a computer programming language used to manage data in relational database management systems. It was originally based upon relational algebra, so if you know basic algebra, you can easily learn SQL. SQL and databases are most commonly used for e-commerce sites (every time you search for a product or log on to Amazon, you have accessed a database), but they are used for a variety of business and personal uses.

SQL Basics Tutorial

  • Open up the database program of your choice. This could be Microsoft Access, SQL Server, or Oracle. Create a few sample fields, such as First Name, Last Name, Address, City, State, and Zip. Then add a few sample records to test on.

  • Write your first query by typing out "SELECT FROM table_name" where table_name is the name of the table you created. This example returns every value from every field in the table within your database (the indicates all). You can also say "SELECT field_name FROM table_name" to select only the field_name field from your table.

  • Add to your last statement with the WHERE clause. The WHERE clause specifies which fields you want to return based on a certain value. "SELECT * FROM table_name WHERE last_name = 'Morgan' " will search for "Morgan" in the last_name field and returns all records from the table in which the person's last name is Morgan. Note that if you are searching for a string (letters or words), you will need single quotes around the name. If you are searching for a number, you don't need the quotes.

  • Add to your last statement once again by using the ORDER BY clause. "SELECT FROM table_name ORDER BY last_name" will order your recordset by the person's last name in alphabetical order. You can also do "SELECT FROM table_name ORDER BY age" and it will order by the person's age (add DESC after the field name you wish to order by to list the names in descending order).

  • Create a new query by typing the INSERT INTO statement. The INSERT INTO statement inserts a new row into the table that you specify. "INSERT INTO table_name VALUES ('Courtney','Morgan',14)" will add the first name of Courtney, the last name of Morgan, and the age of 14 into your table. Likewise, if you want to delete someone from your table, you will use the DELETE statement. "DELETE FROM table_name WHERE last_name = 'Morgan' AND first_name = 'Courtney' " will delete Courtney Morgan from your table.

  • Create another new query. Use the UPDATE statement. This will update a record instead of adding or deleting one. "UPDATE table_name SET address = '555 Hollywood Blvd', city = 'Los Angeles' WHERE last_name = 'Morgan' AND first_name = 'Courtney' " will update Courtney Morgan's address to 555 Hollywood Blvd and her city to Los Angeles.

Tips & Warnings

  • SQL is not case sensitive, so you can use upper or lower case. Many people use uppercase because it is easier to distinguish the SQL from the rest of your code.


  • Photo Credit computer image by fotografiche.eu from Fotolia.com
Promoted By Zergnet



You May Also Like

  • MySQL Script Tutorial

    Typing SQL statements at the MySQL prompt is time-consuming and error-prone. If you have a long sequence of statements, or statements that...

  • How to Write SQL Scripts

    SQL, or Structured Query Language, which allows for the creation and editing of databases, is one of the easiest Web-based programming languages...

  • SQL Navigator Tutorial

    SQL Navigator Tutorial. SQL Navigator is a tool that helps SQL users and ... PL/SQL code allows users to troubleshoot scripts as...

  • How to Execute SQL Script From Visual Basic

    The latest version of Visual Basic provides a rich data access layer that allows for object-oriented abstraction of the data used in...

  • How to Learn Informatica

    Look on Bouboune's Blog (see Resources) for Informatica training tutorials. Start with the beginner's tutorial "ETL Tools - Informatica Training."

  • Tutorial on SQL Triggers & Stored Procedures

    A SQL Server Script Tutorial. Tutorial for Connecting to MySQL With JavaScript. Featured. Facebook Pages. Watch Video. Great Games for Your Phone....

  • SQL Tutorial: Format

    Use the "format" function within a SQL statement to change the way that information within a column is returned. Specifiy the column...

  • How to Connect Visual Basic to SQL

    How to Connect Excel to SQL Using Visual Basic. The spreadsheet application Microsoft Excel has Visual Basic, ... How to Execute SQL...

  • How to Write a Looping SQL Script

    As an example, you can run a script that executed the update_list procedure endlessly until the date in the database was no...

  • How to Run SQL Script From a Microsoft SQL Server Express

    SQL Server Express is a free version of SQL Server that you can use to create desktop and Web-based database applications. Developers...

Read Article

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

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