sql key points

2
SQL (Structured Query Language) Summary For Module 5 you need to be able to explain DDL (Data Definition Language) – used to define a database for example: CREATE TABLE Student (Name varchar(20) NOT NULL DoB date NOT NULL) creates a table with 2 columns, neither of which can contain blanks. DML (Data Manipulation Language) used to extract information from a database You are expected to be able to write or carry out SQL statements that include the key words: Select - to specify the fields (columns) to be listed From - to specify the table(s) Where - to set conditions such as “Age > 21” In - used inside a Where clause: it is followed by a list of allowed values GroupBy – used to get totals for different categories within a table OrderBy - to specify the order in which rows should be displayed “Where” clauses may also include operators such as =, <>, <, >, AND, OR So the command SELECT Name, TutorGroup FROM Students WHERE DoB < 01/01/1985 ORDER BY DoB;

Upload: robj

Post on 12-Nov-2014

182 views

Category:

Documents


1 download

DESCRIPTION

CPT 5 Course document.

TRANSCRIPT

SQL (Structured Query Language) Summary

For Module 5 you need to be able to explain

DDL (Data Definition Language) – used to define a database

for example: CREATE TABLE Student(Name varchar(20) NOT NULL DoB date NOT NULL)

creates a table with 2 columns, neither of which can contain blanks.

DML (Data Manipulation Language) used to extract information from a database

You are expected to be able to write or carry out SQL statements that include the key words:

Select - to specify the fields (columns) to be listed

From - to specify the table(s)

Where - to set conditions such as “Age > 21”

In - used inside a Where clause: it is followed by a list of allowed values

GroupBy – used to get totals for different categories within a table

OrderBy - to specify the order in which rows should be displayed

“Where” clauses may also include operators such as =, <>, <, >, AND, OR

So the command

SELECT Name, TutorGroupFROM StudentsWHERE DoB < 01/01/1985ORDER BY DoB;

would list two columns of data from table “Students”, the Name and Tutor Group, showing only the students born before 1st January 1985. They would be arranged in order of age.

See chapter 60 of Heathcote for further examples.