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.

  1. SQL Basics Tutorial

    • 1

      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.

    • 2

      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.

    • 3

      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.

    • 4

      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).

    • 5

      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.

    • 6

      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.
Related Searches

References

Resources

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

Related Ads

Related Searches
Check It Out

How to Avoid Buying a Laptop with Malware