Thingy 5 acme blecco wa adam p widget 8 blecco foobar

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 25 Blecco 4 5/29/2013 5/29/2013 Relational Databases Joins Result of a natural join Product Cost Vendor State Contact Widget $10 Acme MA Linda A. Thingy $5 Acme MA Linda A. Widget $8 Blecco WA Adam P. Foobar $25 Blecco WA Adam P. Relational Databases Structured Query Language (SQL) Standard language for accessing a relational database, standardized by American National Standards Institute (ANSI); SQL-92 Open, but not really Common functions are mostly the same across products Most vendors have proprietary extensions Subsets of SQL Data Definition Language (DDL) Data Manipulation Language (DML) Data Control Language (DCL) 5 5/29/2013 5/29/2013 Relational Databases DDL Examples Used to create and modify database objects CREATE DATABASE Bookstore CREATE TABLE tBooks ( BookID INT IDENTITY(1,1) PRIMARY KEY, Title VARCHAR(30) NOT NULL, PubDate DATE NOT NULL, [Description] VARCHAR(50), Category INT NOT NULL ) Relational Databases DML Examples Select data to view SELECT * FROM tAuthors SELECT AuthID, FirstName, LastName FROM tAuthors SELECT AuthID, FirstName, LastName, Phone FROM tAuthors WHERE City = ‘Boston’ SELECT FirstName, LastName, Phone FROM tAuthors WHERE AuthID = 249 6 5/29/2013 5/29/2013 Relational Databases DML Examples Using SELECT to join tables SELECT AuthID, FirstName, LastName, Phone, BookID, Title, PubDate, Description FROM tAuthors, tBooks WHERE tAuthors.AuthID = tBooks.AuthID SELECT AuthID, FirstName, LastName, Phone, BookID, Title, PubDate, Description FROM tAuthors INNER JOIN tBooks ON tAuthors.AuthID = tBooks.AuthID Relational Databases DML Examples Insert, update and delete data INSERT INTO tBooks (Title, PubDate, [Description], Category) VALUES (‘Database Design’, GETDATE(), ‘How to design a database’, 3) UPDATE tAuthors ‘617-555SET Phone = ‘617-555-1234’ WHERE AuthID = 5 DELETE FROM tAuthors WHERE AuthID = 5 7 5/29/2013 5/29/2013 Relational Databases DCL Examples Set security options on database objects GRANT INSERT, UPDATE, DELETE ON tAuthors TO Mary, John REVOKE CREATE TABLE FROM Joe DENY ALL ON tAuthors, tBooks TO Sally Relational Databases Views A view is a virtual table Abstracts the underlying table structures Abstracts a (possibly complex) query Provides security abstraction from table In SQL Server, a view can be Indexed Updated and inserted into 8 5/29/2013 5/29/2013 Relational Databases View Definition Example CREATE VIEW vwCustomerOrders AS SELECT o.OrderId, c.CompanyName FROM Customers c INNER JOIN Orders...
View Full Document

This note was uploaded on 04/04/2014 for the course CS 5950 taught by Professor Staff during the Summer '08 term at Western Michigan.

Ask a homework question - tutors are online