0% found this document useful (0 votes)
29 views

SQL Is Structured Query Language PDF

Uploaded by

Manish Choudhury
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

SQL Is Structured Query Language PDF

Uploaded by

Manish Choudhury
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SQL is Structured Query Language,

which is a computer language for storing,


manipulating and retrieving data stored in a relational
database. SQL is the standard language for Relational
Database System.
All the Relational Database Management Systems
(RDMS) like MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server use SQL as their
standard database language.

Also, they are using different dialects, such as:


 MS SQL Server using T-SQL,
 Oracle using PL/SQL
 MS Access version of SQL is called JET SQL (native
format) Etc.
When you are executing an SQL
command for any RDBMS, the system
determines the best way to carry
out your request and SQL engine
figures out how to interpret the task.
There are various components included in this
process.
These components are –
 Query Dispatcher
 Optimization Engines
 Classic Query Engine
 SQL Query Engine, etc.
A classic query engine handles
all the non-SQL queries,
but a SQL query engine
won't handle logical files.
Following is a simple diagram showing the SQL
Architecture:
DDL - Data Definition Language

DML - Data Manipulation Language


DCL - Data Control Language

This is one of the most popular Microsoft products.


Microsoft Access is an entry-level database management
software.
MS Access database is not only inexpensive but also a
powerful database for small-scale projects.
MS Access uses the Jet database engine, which utilizes a
specific SQL language dialect (sometimes referred to as Jet
SQL). MS Access comes with the professional edition of
MS Office package. MS Access has easyto-use intuitive
graphical interface
 1992 - Access version 1.0 was released.
 1993 - Access 1.1 released to improve compatibility with inclusion the
Access Basic programming language.
 The most significant transition was from Access 97 to Access 2000
 2007 - Access 2007, a new database format was introduced ACCDB
which supports complex data types such as multi valued and attachment
fields. Features
 Users can create tables, queries, forms and reports and connect them
together with macros.
 Option of importing and exporting the data to many formats
including Excel, Outlook, ASCII, dBase, Paradox, FoxPro, SQL
Server, Oracle, ODBC, etc.
 There is also the Jet Database format (MDB or ACCDB in Access
2007), which can contain the application and data in one file. This
makes it very convenient to distribute the entire application to another
user, who can run it in disconnected environments.
 Microsoft Access offers parameterized queries. These queries and
Access tables can be referenced from other programs like VB6 and
.NET through DAO or ADO
Create a new table with three
columns

1 CREATE TABLE t (
2 id INT PRIMARY KEY,
3 name VARCHAR NOT NULL,
4 price INT DEFAULT 0
5 );

Delete the table from the


database

DROP TABLE t ;
1
Add a new column to the table

ALTER TABLE t ADD column;


1

Drop column c from the table

ALTER TABLE t DROP COLUMN c ;


1
Add a constraint

1 ALTER TABLE t ADD constraint;


Drop a constraint

ALTER TABLE t DROP constraint


1;

Rename a table from t1 to t2

ALTER TABLE t1 RENAME TO t2;


1
Rename column c1 to c2

ALTER TABLE t1 RENAME c1 TO c


12 ;

Remove all data in a table

TRUNCATE TABLE t;
Insert multiple rows into
a table
1
1 INSERT INTO t(column_li
2 st)
3 VALUES (value_list),
(value_list), …;
Insert rows from t2 into
t1
INSERT INTO t1(column_l
1
ist)
2
SELECT column_list
3
FROM t2;
Update new value in the
column c1 for all rows
1 UPDATE t
2 SET c1 = new_value;
Update values in the
column c1, c2 that match
the condition
1 UPDATE
2 SET c1 = new_value,
3 c2 = new_value
4 WHERE condition;
Delete all data in a
table
1 DELETE FROM t;
Delete subset of rows in
a table
1 DELETE FROM t
2 WHERE condition;

Create a new view that


consists of c1 and c2
1 CREATE VIEW v(c1,c2)
2 AS
3 SELECT c1, c2
4 FROM t;

Create a new view with


check option
CREATE VIEW v(c1,c2)
1
AS
2
SELECT c1, c2
3
FROM t;
4
WITH [CASCADED | LOCAL]
5
CHECK OPTION;
Create a recursive view
CREATE RECURSIVE VIEW v
1 AS
2 select-statement -- anc
3 hor part
4 UNION [ALL]
5 select-statement; -- re
cursive part
Create a temporary view
1 CREATE TEMPORARY VIEW v
2 AS
3 SELECT c1, c2
4 FROM t;
Delete a view
1 DROP VIEW view_name;
Managing indexes
Create an index on c1 and
c2 of the t table
1 CREATE INDEX idx_name
2 ON t(c1,c2);

Create a unique index on


c3, c4 of the t table
CREATE UNIQUE INDEX idx
1
_name
2
ON t(c3,c4)
Drop an index
1 DROP INDEX idx_name;
TRIGGER_TYPE
 FOR EACH ROW
 FOR EACH STATEMENT
Delete a specific trigger
DROP TRIGGER trigger_na
1
me;

Create or modify a
trigger
CREATE OR MODIFY TRIGGE
R trigger_name
1
WHEN EVENT
2
ON table_name TRIGGER_T
3
YPE
4
EXECUTE stored_procedur
e;
WHEN
 BEFORE – invoke before
the event occurs
 AFTER – invoke after
the event occurs
EVENT
 INSERT – invoke for
INSERT
 UPDATE – invoke for
UPDATE

You might also like