Chapter41

Chapter41 - CSIS0278A Introduction to Database Management...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style CSIS0278A Introduction to Database Management Systems Lecture 4: SQL Part 1 Dr. Reynold Cheng Based on the Ch. 3 notes of “Database System Concepts” by A. Silberschatz, H. Korth & S. Sudarshan and notes by Dr. Ho Wai Shing
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2DB040:2 Overview l Data Definition l Basic Query Structure l Set Operations l Aggregation Functions l Null Values Nested Sub-queries Complex Queries Views Modification of Databases Joins
Background image of page 2
3DB040:3 History l IBM Sequel language was developed as a part of the System R project at the IBM San Jose Research Laboratory in early 1970s. l Renamed to Structured Query Language (SQL) l Became ANSI and ISO standard: l SQL-86 l SQL-89 l SQL-92 l SQL-1999 (now Y2K compliant!) l SQL-2003 l SQL-2006 l SQL-2008 l Commercial systems offer most (if not all) features of SQL-92, plus varying features in later specifications, and some proprietary features. l i.e., not all examples here may work in your particular
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4DB040:4 SQL, DDL l SQL provides features in the following areas: l Data definition l Data manipulation l Querying l Updating l Data Definition – specifies info about each relation: l The schema for each relation. l The domain of values associated with each attribute. l Integrity constraints l The set of indices to be maintained for each relation. l Security and authorization info for each relation. l The physical storage structure of each relation on
Background image of page 4
5DB040:5 Domain Types in SQL l char(n): Fixed length character string, with a user- specified length n. l varchar(n): Variable length character string, with a user-specifiedmaximum length n. l int: Integer (a finite subset of integers, machine- dependent) l smallint: Small integer (also machine dependent) l numeric(p, d): Fixed point number, with a user- specified precision of p digits (in total), and d digits to the right of decimal point. l real , double precision : floating point and double- precision floating point numbers respectively (machine-dependent)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6DB040:6 CREATE TABLE Construct l An SQL relation is defined using the CREATE  TABLE command: l CREATE TABLE  R ( A 1 D 1 A 2 D 2 , …,  AnDn , integrity-constraint 1 ,                . .., integrity-constraintk ) l R is the name of the relation l Each Ai is an attribute name in the schema of relation R l Di is the data type of values in the domain of CREATE TABLE Branch   (b_name CHAR(15) NOT NULL,    b_city CHAR(30),    assets INT)
Background image of page 6
7DB040:7 Integrity Constraints in CREATE TABLE l NOT NULL l PRIMARY KEY( A 1 , , An ) l Stating the attributes involved in the primary key. l PRIMARY KEY declaration on an attribute automatically ensures NOT NULL in SQL-92 onwards, but it needs to be explicitly stated in SQL-89 l E.g., b_name is primary key and assets must CREATE TABLE Branch   (b_name CHAR(15),    b_city CHAR(30),    assets INT UNSIGNED,    PRIMARY KEY(b_name) )
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8DB040:8 DROP and ALTER TABLE l DROP TABLE deletes all information about the
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 74

Chapter41 - CSIS0278A Introduction to Database Management...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online