Download SQL (Structured Query Language)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

DBase wikipedia , lookup

Oracle Database wikipedia , lookup

Btrieve wikipedia , lookup

Functional Database Model wikipedia , lookup

Microsoft Access wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Concurrency control wikipedia , lookup

Ingres (database) wikipedia , lookup

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Versant Object Database wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Relational algebra wikipedia , lookup

PL/SQL wikipedia , lookup

SQL wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Transcript
SQL (Structured Query Language)
SQL
•
SQl is a query language and is supported by almost all major
database management systems.
•
It can be used in a database system interactively using a graphical
user interface or prompt so you type your SQL queries or commands
and get the result back or SQL can be embedded in the program.
•
SQL is a declarative language you write simple queries that say what
you want out of the database and queries do not need to describe how
to get the data out of the database.
•
The language is based on the relational algebra.
•
The declarative nature of the language leads to a component of the
database system called query optimizer to be so important.
•
What the query optimizer does is it takes the query written in SQL
and it figures out the best way, the fastest way to execute it.
Select Statement
take a look in a little more detail at select statement
•
Select statement consists of three basic clauses; select clause, from
clause and where clause.
•
The best order to think of these is actually, first from clause then where
clause and then select clause.
•
From identifies the relations you want to query over.
•
Condition is used to combine the relations and to filter the relations.
•
Finally select says you what to return.
•
Relational query languages are compositional meaning when you run a
query over relations you get a relation as a result. It doesn’t have any
name but the schema of the relation is the set of attributes that are
returned.
Summery
•
SQl is very prominent, is supported by all major database systems..
•
It has been standardized over time.
•
It can be used through programs.
•
It can be used interactively.
•
It’s declarative, high-level language.
•
Whose foundations are based on relational algebra.
Our sample database
•
College(cName, state, enrollement)
•
Student(sID, sName,GPA,sizeHS)
•
Apply(sID, cName, major, decision)
(students apply to each college for a specific major one time)
•
Underlined attributes are the key attributes.
•
What is a key: key is an attribute or a set of attribute whose value is
guaranteed to be unique.
•
Given our database we apply some queries against the database.
Queries:
•
1.find Id, name and GPA of those students whose GPA is greater
than 3.6.
•
2.Find the names of the students and the major for which they
applied.
( we want to combine student with apply relation and we have to mention join condition explicitly
although in relational algebra would automatically happen in natural join)
•
We can expect even duplicates as a result of query in SQL. However, this is not the case in
relational algebra. In relational algebra the default is the set model but in SQL the default is
multi-set model.
•
Using Distinct keyword in select clause eliminate any possible duplicates.
•
3. Find
name and GPA of the students whose sizeHS is less than a
thousand, they applied to CS in Stanford and we are going to get the
decision associated with that.
continue…
•
Some notes about the third query( two tables involved, we have the join condition to
make sure we are talking about the same student. We are going to filter the results based on the
size high school, major and the college to which they’re applying)
•
4. Find large campuses that have some one applying to this campus in
CS.(we are going to join college and apply tables .Again there is join condition to make sure we
are talking about the same college and have an enrollment greater than some amount.)
Is there any specific observation after running this query against your database, mention if any.
•
5. we want to get the studentIDs, their name, their GPA, the college
they’re applying to and the enrollment of that college.
•
Question: Is there any order in results when we run SQL queries?
•
SQl, at its heart, is unordered model. That means we can get the result of our queries in any order.
•
If we care about the results SQL provides a clause to order the query results