Saturday, 20 February 2016

SQL Scripting TutorialIn Feburary 2016 20,

In Feburary 2016 20,
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.
In Feburary 2016 20,

No comments:

Post a Comment