Professional Documents
Culture Documents
Lec-4 Queries in Database
Lec-4 Queries in Database
Lecture 4
Queries
The information can be obtained from the Database by asking some direct questions known as Queries. Such questions involves the data stored in the DBMS. e.g. What are the Name of all students stored in Database Student? DBMS provides a specialized language, called the Query Language in which queries can be posed.
Database Languages
DDL Data Definition Language SDL Storage Definition Language VDL View Definition Language DML Data Manipulation Language (For data manipulations like insertion, deletion, update, retrieval, etc.) DCL - Data Control language.
DBMS Languages
Data Definition Language (DDL) Used by the DBA and database designers to specify the conceptual schema of a database. In many DBMSs, the DDL is also used to define internal and external schemas (views). In some DBMSs, separate storage definition language (SDL) and view definition language (VDL) are used to define internal and external schemas.In General storage definition language (SDL) and view definition language (VDL) are the part of DDL. Data Manipulation Language (DML) Used to specify database retrievals and updates (insertion, deletion, modifications) - DML commands (data sublanguage) can be embedded in a general-purpose programming language (host language). - Alternatively, stand-alone DML commands can be applied directly (query language).
Queries
Find all courses that Mary takes SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=Mary and S.ssn = T.ssn and T.cid = C.cid
What happens behind the scene ?
Query processor figures out how to answer the query efficiently.
SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=Mary and S.ssn = T.ssn and T.cid = C.cid
sid=sid name=Mary
cid=cid
Students
Takes
Courses
The typical usage is simply DROP objecttype objectname. For example, the command to drop a table named employees would be: DROP TABLE employees;
The DROP statement is distinct from the DELETE and (non-standard) TRUNCATE statements, in that they do not remove the table itself. For example, a DELETE statement might delete some (or all) data from a table while leaving the table itself in the database, whereas a DROP statement would remove the entire table from the database.
DML
High-level DML: set-oriented, declarative Low-level DML: record-oriented, procedural Types of DML
data sublangauge: DML embedded in a general purpose language (for DBAs) query language: high-level, interactive, standalone DML (casual end users) user-friendly interface for DML (nave users)