Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
The IBM’s System/R was not the first DBMS. The first to market was Relational Software's product named Oracle
The second was Relational Technology's Ingres. IBM then released improved products in 1982
named SQL/DS and DB2. Oracle and DB2 in nth generation forms while the Ingres technology was bought by Computer Associates
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
SQL is a open language without corporate ownership. The ANSI-SQL (American National Standards
Institute) group has published three standards over the years:SQL89 (SQL1)SQL92 (SQL2)SQL99 (SQL3)
The majority of the language has not changed through these updates.
The SQL standard from ANSI is considered the "pure" SQL and called ANSI-SQL.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Every DBMS vendor wants their products to be different. So most products offers extra features, these additions are generally not compatible with competitor's SQL products.
It is always safest to stick with pure SQL The enhancements are not all bad because these extensions are
very useful. For example, most DBMS sold today have an automatic way to
assign a serial number feature since serial numbering is so common. However, the method of implementation is not uniform.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
In SQL, a VIEW is a virtual relation based on the result-set of a SELECT statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. In some cases, we can modify a view and present the data as if the data were coming from a single table.
Syntax: CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
When we say Relation, it could be a Table or a View. There are three kind of relations:
1. Stored relations tables
We sometimes use the term “base relation” or “base table”
2. Virtual relations views
3. Temporary results
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Example: Create a view with title and year and made by Paramount studio.
Movie (title, year, length, inColor, studioName, producerC#)
CREATE VIEW ParamountMovie ASSELECT title,yearFROM MovieWHERE studioName = ‘Paramount’;
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
A view could be used from inside a query, a stored procedure, or from inside another view. By adding functions, joins, etc., to a view, it allows us to present exactly the data we want to the user.
SELECT titleFROM ParamountMovieWHERE year = ‘1979’;
Have same result asSELECT titleFROM MovieWHERE studioName = ‘Paramount’ AND year = ‘1979’;
View
Table
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Query involving both view and table
SELECT DISTINCT starName
FROM ParamountMovie, StarsIn
WHERE title = movieTitle AND year = movieYear;
Table
View
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Sometime, we might want to distinguish attributes by giving the different name.
CREATE VIEW MovieProd (movieTitle, prodName) AS SELECT title, nameFROM Movie, MovieExecWHERE producerC# = cert#;
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
When we modify a view, we actually modify a table through a view. Many views are not updateable. Here are rules have been defined in SQL for updateable views:
selecting (SELECT not SELECT DISTINCT) some attributes from one relation R (which may itself be an updateable view) The WHERE clause must not involve R in a subquery. The list in the SELECT clause must include enough
attributes that will allow us to insert tuples into the view as well as table. All other attributes will be filled out with NULL or the proper default values.
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
INSERT INTO ParamountMovieVALUES (‘Star Trek’, 1979);To make the view ParamountMovie updateable, we need to add attribute studioName to it’s SELECT clause because it makes more sense if the studioName is Paramount instead of NULL.
CREATE VIEW ParamountMovie AS SELECT studioName, title, yearFROM MovieWHERE studioName = ‘Paramount’;
ThenINSERT INTO ParamountMovieVALUES (‘Paramount’, ‘Star Trek’, 1979);
Title year length inColor studioName producerC#
‘Star Trek’ 1979 0 NULL ‘Paramount’ NULL
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Suppose we wish to delete all movies with “Trek” in their title from the updateable view ParamountMovie.
DELETE FROM ParamountMovieWHERE title LIKE ‘%Trek%’;
It is turned into the base table delete
DELETE FROM MovieWHERE title LIKE ‘%Trek%’ AND studioName = ‘Paramount’;
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
UPDATE from an updateable viewUPDATE ParamountMovieSET year = 1979WHERE title = ‘Star Trek the Movie’;
It is turned into the base table updateUPDATE MovieSET year = 1979WHERE title = ‘Star Trek the Movie’ AND studioName = ‘Paramount’;
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
DROP view: All views can be dropped, whether or not the view is updateable.
DROP VIEW ParamountMovie;
DROP VIEW does not affect any tuples of the underlying relation (table) Movie.
However, DROP TABLE will delete the table and also make the view ParamountMovie unusable.
DROP TABLE Movie
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
ADDRESS:
SCO -15, Dayal Bagh,
Near Hanuman Mandir
Ambala Cantt-133001
Haryana
Ph. No.: 9729666670, 8222066670 &0171-4000670
Email ID: [email protected]
Website: www.batracomputercentre.com
Website: www.batracomputercentre.comPh. No.: 8222066670, 4000670
Email: [email protected]
Recommended