Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
12Activity
0 of .
Results for:
No results containing your search query
P. 1
LESSON 7 - Introduction to SQL for Visual Basic Programming

LESSON 7 - Introduction to SQL for Visual Basic Programming

Ratings:
(0)
|Views: 231|Likes:
Published by api-3709816

More info:

Published by: api-3709816 on Oct 16, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

INTRODUCTION TO SQL FOR VISUAL BASIC PROGRAMMING
7
If you want to work with databases, you must learn to speak their language. Databases speak
STRUCTURED QUERY LANGUAGE, better known as SQL, which was invented by E. F.
Codd in the 1970\u2019s.
SQL is an ANSI (American National Standards Institute) standard computer language

for accessing and manipulating database systems.SQL statements are used to retrieved and update data in a database.SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.

What is SQL?
\u2022
SQL stands forStructuredQueryLanguage.
\u2022
SQL is a standard computer language for accessing and manipulating databases.
\u2022
SQL can retrieve or extract data from a database.
\u2022
SQL can insert new records in a database.
\u2022
SQL can update and delete records from a database.
\u2022
SQL is easy to learn.
SQL encompasses two distinct categories of statements: Data Definition language (DDL)

and Data Manipulation Language (DML). TheDDL subset includes a group of statements that allow you to create database structures, such as tables, fields, indices and so on. TheDML subset includes all the commands that allow you to query and modify the data in the database, add new records, or delete existing ones. Most of the time, you\u2019ll use onlyDML statements to retrieve and update data stored in a database.

Two Categories of SQL statements:
1.SQL Data Definition Language (DDL) \u2013 permits database tables to be created or
deleted. Using SQL DDL, you can define indexes (keys), specify links between tables,
and impose constraints between database tables.
The most importantDDL commands inSQL are:

a.CREATE TABLE \u2013 creates a new database table.
b.ALTER TABLE \u2013 alters (changes) a database table.
c.DROP TABLE \u2013 deletes a database table.
d.CREATE INDEX \u2013 creates an index (search key)
e.DROP INDEX \u2013 deletes an index.

2.SQL Data Manipulation Language (DML) \u2013 commands that modify or manipulate
records in a database table.
Commands that form the Data Manipulation Language:
a.SELECT \u2013 extracts data from a database table.
b.UPDATE \u2013 updates data in a database table.
Information and Communication Technology Department
Palompon Institute of Technology
53
Introduction to SQL
INTRODUCTION TO SQL FOR VISUAL BASIC PROGRAMMING
7
c.DELETE \u2013 deletes data from a database table.
d.INSERT \u2013 inserts new data into a database table.
A database most often contains one or more tables. Each table is identified by a name (e.g.
\u201cCustomers\u201d or \u201cOrders\u201d). Tables contain records (row) with data.
Below is an example of a table called\u201cPer sons\u201d
LastName
FirstName
Address
City
Hansen
Ola
Timotein 20
Sandnes
Stevendson
Tove
Borgvn 23
Sandnes
Pettersen
Karl
Storgt 20
Stavanger
The table above contains three records (one for each person) and four columns (LastName,
FirstName, Address, City).
TheSELECT statement selects columns of data from a database table. The tabular result is
stored in a result table called ther esultset.
Syntax:
SELECT column-name(s) FROM table-name
Example 1: Select Columns from a Table.
To select the columns named \u201cLastName\u201d and \u201cFirstName\u201d, use aSELECT statement like this:
SELECT LastName, FirstName FROM Persons
The\u201cPe r sons \u201d table:
LastName
FirstName
Address
City
Hansen
Ola
Timotein 20
Sandnes
Stevendson
Tove
Borgvn 23
Sandnes
Pettersen
Karl
Storgt 20
Stavanger
The result:
LastName
FirstName
Hansen
Ola
Stevendson
Tove
Pettersen
Karl
Example 2:Select all Columns
Information and Communication Technology Department
Palompon Institute of Technology
54
SQL Database Tables
The SELECT Statement
INTRODUCTION TO SQL FOR VISUAL BASIC PROGRAMMING
7
To select all columns from the\u201cPer sons\u201d table, use an * (asterisk) symbol instead of column
name, like this:
SELECT * FROM Persons
The result:
LastName
FirstName
Address
City
Hansen
Ola
Timotein 20
Sandnes
Stevendson
Tove
Borgvn 23
Sandnes
Pettersen
Karl
Storgt 20
Stavanger
To conditionally select data from a table, aWHERE clause can be added to theSELECT
statement.
Syntax:
SELECT column-name FROM table-name WHERE column Operator value
WithWHERE clause, the following operator can be used:
Operator
Description
=
Equal
<>
Not equal
>
Greater than
<
Less than
>=
Greater than or equal
<=
Less than or equal
BETWEEN
Between an inclusive range
LIKE
Search for a pattern
Note: In some versions of SQL, the Not Equal operator <> can be written as !=
Example:To select the persons living in the city \u201cSandnes\u201d, we add a WHERE clause to the
SELECTstatement:
SELECT * FROM Persons WHERE City ='Sandnes'
The\u201cPe r sons\u201d table:
LastName
FirstName
Address
City
Year
Hansen
Ola
Timotein 20
Sandnes
1951
Stevendson
Tove
Borgvn 23
Sandnes
1978
Stevendson
Stale
Kaivn 18
Sandnes
1980
Pettersen
Karl
Storgt 20
Stavanger
1960
The result:
Information and Communication Technology Department
Palompon Institute of Technology
55
The WHERE Clause

Activity (12)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
John Anand liked this
Andi Sarmiento liked this
Eswari24 liked this
Tom Horrigan liked this
userraj liked this
adimulapu liked this
jdelakruz523 liked this
romeofatima liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->