In accordance with the relational data model, the database is treated as a set of tables. Relationships are represented by values in tables, and data is retrieved by specifying a result table that can be derived from one or more base tables. Here are a few examples of what SQL looks like:
INSERT is used to add rows or tuples to an existing table:
INSERT INTO My_table
(field1, field2, field3)
VALUES
('test', 'N', NULL);
UPDATE is used to modify the values of a set of existing table rows:
UPDATE My_table
SET field1 = 'updated value'
WHERE field2 = 'N';
DELETE removes zero or more existing rows from a table:
DELETE FROM My_table
WHERE field2 = 'N';
The following query would render the student ID's, in numerical order, of those students who scored an A in a particular course.
SELECT DISTINCTROW STUDENT_ID, GRADE
FROM GRADES
WHERE GRADES="A"
ORDER BY STUDENT_ID
This is an example of a SELECT query that returns a list of expensive cars. The query retrieves all rows from the Car table in which the price column contains a value greater than 60,000.00. The result is sorted in ascending order by model. The asterisk (*) in the select list indicates that all columns of the Car table should be included in the result set.
SELECT *
FROM Car
WHERE price > 60,000.00
ORDER BY model
Many SQL tutorials are available online for those interested in learning the language. W3Schools.com and SQLcourse.com provide introductory tutorials, while other sites like Microsoft's SQL Server Training provide in-depth information for the use of their own SQL software package.
Sources:
Jessup, Valadich & Wade. (2006). Information Systems Today: Why IS Matters.
Toronto: Pearson—Prentice Hall.
IBM. "Structured Query Language (SQL)". Database Systems.
<http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/c0004100.htm>
Accessed April 3, 2009.
No comments:
Post a Comment