Structured Query Language: Difference between revisions
imported>Tom Morris (simple cleanup and subpages) |
imported>Tom Morris (fixed layout and made syntax slightly more readable) |
||
Line 5: | Line 5: | ||
== Examples == | == Examples == | ||
The syntax of a simple SQL query: | The syntax of a simple SQL query: | ||
<code> | <code> | ||
SELECT {fields} FROM {table} WHERE {conditions}; | |||
</code> | |||
Here is a simple example that returns details from a table called 'students', only if the row has a GPA higher than 3: | |||
<code> | |||
SELECT name, rollnum, totalmarks FROM students WHERE gpa > 3; | |||
</code> | |||
Queries can be nested in order to give more specific results as desired. |
Revision as of 16:22, 16 July 2008
Structured Query Language (SQL) is a simple language designed for querying and managing Relational Database Management Systems (RDBMS). RDBMSs organize data using tables, where each table has named column(s). Each column has one datatype, and data is stored as rows intersecting with these columns and therefore satisfy the datatype of the corresponding column. For example, a student table could have two columns, student_id and student_name. If I want to insert data into this table, I would insert a row of two values, a student_id e.g. 001 and a student_name e.g. Claire. It is this concept of tables that is the basis of SQL, which has become the defacto standard adopted by most database management systems vendors. However, most vendors provide an extension to SQL to serve various functions ranging from the integration of procedural constructs to exception handling.
Examples
The syntax of a simple SQL query:
SELECT {fields} FROM {table} WHERE {conditions};
Here is a simple example that returns details from a table called 'students', only if the row has a GPA higher than 3:
SELECT name, rollnum, totalmarks FROM students WHERE gpa > 3;
Queries can be nested in order to give more specific results as desired.