Sunteți pe pagina 1din 19

MS Access – Working

with Databases
 SQL is a standard language for storing,
manipulating and retrieving data in
databases.
 SQL stands for Structured Query Language
What is SQL?  SQL lets you access and manipulate
databases
 SQL became a standard of the American
National Standards Institute (ANSI) in 1986,
and of the International Organization for
Standardization (ISO) in 1987
 SQL can execute queries against a database
 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
What Can SQL
 SQL can create new databases
do?
 SQL can create new tables in a database
 SQL can create stored procedures in a database
 SQL can create views in a database
 SQL can set permissions on tables, procedures, and
views
Some database systems require a
semicolon at the end of each SQL
statement.
Semicolon
after SQL Semicolon is the standard way to
separate each SQL statement in
Statements? database systems that allow more than
one SQL statement to be executed in the
same call to the server.
 SELECT - extracts data from a database
 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a database
Some of The  CREATE DATABASE - creates a new database
Most  ALTER DATABASE - modifies a database
Important SQL  CREATE TABLE - creates a new table
Commands  ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index
 The SELECT statement is used to select data
The SQL from a database.
SELECT
 The data returned is stored in a result table,
Statement called the result-set.
SELECT column1, column2, ...
FROM table_name;
SELECT
Syntax ->Here, column1, column2, ... are the
field names of the table you want to
select data from.
If you want to select all the fields available
SELECT in the table, use the following syntax:
Syntax
SELECT * FROM table_name;
The SELECT DISTINCT statement is used
to return only distinct (different) values.
The SQL
Inside a table, a column often contains
SELECT
many duplicate values; and sometimes
DISTINCT you only want to list the different
Statement (distinct) values.
SELECT DISTINCT column1, column2, ...
FROM table_name;
SELECT
DISTINCT
Example:
Syntax
SELECT DISTINCT Country FROM Custom
ers;
The WHERE clause is used to filter
The SQL records.
WHERE
Clause The WHERE clause is used to extract only
those records that fulfill a specified
condition.
SELECT column1, column2, ... FROM
WHERE table_name WHERE condition;
Syntax: Example:
SELECT * FROM Customers WHERE
Country='Mexico';
The SQL
INSERT INTO The INSERT INTO statement is used to
Statement insert new records in a table.
It is possible to write the INSERT INTO
statement in two ways.
INSERT INTO The first way specifies both the column
Syntax names and the values to be inserted:
INSERT INTO table_name (column1,
column2, column3, ...) VALUES (value1,
value2, value3, ...);
If you are adding values for all the
columns of the table, you do not need to
specify the column names in the SQL
query. However, make sure the order of
the values is in the same order as the
columns in the table. The INSERT INTO
syntax would be as follows:
INSERT INTO table_name VALUES
(value1, value2, value3, ...);
The SQL
The UPDATE statement is used to
UPDATE
modify the existing records in a
Statement
table.
UPDATE table_name SET column1 =
value1, column2 = value2, ... WHERE
condition;
UPDATE Example:
Syntax:
UPDATE Customers SET ContactName =
'Alfred Schmidt', City= 'Frankfurt' WHERE
CustomerID = 1;
SQL DELETE
The DELETE statement is used to
Statement
delete existing records in a table.
DELETE FROM table_name WHERE
DELETE condition;
Syntax EXAMPLE:
DELETE FROM Customers WHERE
CustomerName='Alfreds Futterkiste';

S-ar putea să vă placă și