Home > Computers & Technology > Software > Software & Web Development
Created on: January 22, 2008
Before we dive into the basics of SQL it is pertinent to give a little background on it's origins. SQL was originally coined SEQUEL by IBM in about 1975. It stands for Structured English QUEry Language. At the time, IBM was researching the commercial viability of a relational database system, based on the work of Dr E. Codd and his seminal paper on the relational model published in 1970. SQL is still often pronounced 'see-quel' even today, although the more common term now is 'es-que-el.'
There are many relational database systems now available. The most well known arguably being: Microsoft SQL Server, Oracle, MySql and PostgreSQL. Each system has it's own proprietry implementation of the SQL language. But they all support the SQL99 standard at a minimum.The latest standard at the time of writing is SQL 2006. Each vendor also supplies a command line or GUI client into which SQL queries can be typed and executed against the data stored in the database. Check your documentation for how to use it.
The most basic of SQL Queries is the single select statement. Before we see how to create one and see what it does, it is helpful to describe a database table against which we can work.
tbName
dbNameId dbFirstName dbLastName dbMiddleName
1 John Smith Andrew
2 John Doe NULL
3 Susan Wells Alice
4 Denise Taylor Trudy
The table is a convenient way of representing a set of tuples (rows) in a relation (table). The first column is the key that uniquely identifies each tuple, known as the Primary Key. The other columns are the attributes of each tuple. It is possible for an attribute to be unknown, John Doe's middle name for example is unknown. Unknown attributes are represented as 'NULL' in relational databases.
You can create this table in your database using the following SQL.
CREATE TABLE tbName
(
dbNameId int identity(1,1) Primary Key,
dbFirstName varchar(32) NOT NULL,
dbLastName varchar(32) NOT NULL,
dbNiddleName varchar(32) NULL
)
You can then populate the table with data using INSERT statements.
INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('John', 'Smith', 'Andrew')
INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('John', 'Doe', NULL)
INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('Susan', 'Wells', 'Alice')
INSERT INTO tbName (dbFirstName, dbLastName, dbMiddleName)
VALUES('Denise', 'Taylor', 'Trudy')
To retrieve all the rows from the table, or more correctly, retrieve all the attributes of each tuple in the tbName relation. We use the
Below are the top articles rated and ranked by Helium members on:
Retrieving data with SQL queries: An introduction
by Ray Cook
SQL (Structured Query Language, pronounced SEQUEL) has been around now for about 30 years. SQL provides a n English-like
by Joseph Love
Throughout 20+ years in the Information field, I've taught several developers how to interact with a database. Although
by Raj Kumar
The most common SQL command is SELECT statement which falls under data manipulation language (DML) group of statements.
by Holly Styles
Before we dive into the basics of SQL it is pertinent to give a little background on it's origins. SQL was originally coined
Helium Debate
Cast your vote!
Is Microsoft Internet Explorer 8's version targeting good or bad?
Click for your side.
Featured Partner
MENTOR - National Mentoring Partnership
MENTOR has partnered with Helium, giving you the chance to write for a cause. Browse MENTOR's featured titles, pick an issue and write! You can also donate your article earnings. Share what you know, learn new perspectives...more