Chapter41 - CSIS0278A Introduction to Database Management...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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) l float(n): Floating point number, with a user-specified
Image of page 5

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

View Full Document Right 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)
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 be non-negative CREATE TABLE Branch   (b_name CHAR(15),    b_city CHAR(30),    assets INT UNSIGNED,    PRIMARY KEY(b_name) )
Image of page 7

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

View Full Document Right Arrow Icon
8DB040:8 DROP and ALTER TABLE Constructs l DROP TABLE deletes all information about the dropped relation from the database.
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '10
  • DR
  • Relational model, perryridge branch, Basic Query Structure, Sub-queries Data Definition, Data Definition Complex

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern