CSIS 350 Lecture 22: Creating Database Tables using SQL DDL Statements, Study notes of Database Management Systems (DBMS)

An overview of sql ddl statements used to create database tables, including create table, alter table, drop table, insert, update, and delete. The document also covers data types, constraints, and relationships in sqlserver, oracle, and mysql. Students will learn how to define primary keys, foreign keys, and constraints, as well as how to create relationships between tables.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-pwy
koofers-user-pwy ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 350 โ€“ Lecture 22
Exam Results
15 exams
Mean 75.17
Median 76.00
Max 97.00
Distribution: 40s: 1 50s: 2 60s: 3 70s: 2 80s: 4 90s: 3
Let's go over problems 6 and 7
Chapter 7
This chapter takes a lot of what we've been doing, and brings it back to SQL for actually
defining the database tables!
Remember, there are two varieties of SQL statements:
- DML, such as SELECT, INSERT
- DDL
We finally get to start looking at some DDL.
Note: the DDL in the book is specific to SQL Server. While most of the features are the
same in all DBMSs, there are differences.
This chapter uses a case-study for its database: The View Ridge Art Gallery โ€“ see slides
1 to 3.
So, how do we convert this DB design (slide 3) to actual database tables? We are going to
use SQL DDL statements:
- CREATE TABLE
- ALTER TABLE
- DROP TABLE
Once we've created the tables, we need to put data in them. Use DML statements:
- INSERT
- UPDATE
- DELETE
Let's look at what is involved in creating some of these tables. Let's start with the
ARTIST and WORK tables. See slide 4.
Note that this slide has some other notations on it describing the required parent actions.
- D:R means to restrict delete
pf3

Partial preview of the text

Download CSIS 350 Lecture 22: Creating Database Tables using SQL DDL Statements and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

CSIS 350 โ€“ Lecture 22

Exam Results 15 exams Mean 75. Median 76. Max 97. Distribution: 40s: 1 50s: 2 60s: 3 70s: 2 80s: 4 90s: 3 Let's go over problems 6 and 7 Chapter 7 This chapter takes a lot of what we've been doing, and brings it back to SQL for actually defining the database tables! Remember, there are two varieties of SQL statements:

  • DML, such as SELECT, INSERT
  • DDL We finally get to start looking at some DDL. Note: the DDL in the book is specific to SQL Server. While most of the features are the same in all DBMSs, there are differences. This chapter uses a case-study for its database: The View Ridge Art Gallery โ€“ see slides 1 to 3. So, how do we convert this DB design (slide 3) to actual database tables? We are going to use SQL DDL statements:
  • CREATE TABLE
  • ALTER TABLE
  • DROP TABLE Once we've created the tables, we need to put data in them. Use DML statements:
  • INSERT
  • UPDATE
  • DELETE Let's look at what is involved in creating some of these tables. Let's start with the ARTIST and WORK tables. See slide 4. Note that this slide has some other notations on it describing the required parent actions.
  • D:R means to restrict delete

o D:C means cascade deletes

  • I:SD means to set default values on insert
  • U:R and U:C also. CREATE TABLE The CREATE TABLE statement is used to create relations. Each column is the table is described by 3 parts:
  • column name
  • data type
  • optional constraints See slide 6 Notes:
  • numeric( 4, 0 ) means a 4 digit number with no digits after the decimal point
  • identity( 1, 1 ) means that this column is a surrogate key. It's initial value is 1 and it increments by 1. (SQL Server syntax)
  • Each line is separated by a comma
  • Put ');' at end on separate line to make it easy to find
  • CONSTRAINT is used to define keys Slide 7 โ€“ same statement in mySQL
  • Note that the surrogate key is defined using AUTO_INCREMENT
  • This starts at 1 and increments by 1 by default Slides 8 to 10 โ€“ Data types for SQLServer, Oracle, and mySQL Constraints Go back to slide 7. The CONSTRAINT clause is used to add constraints to a relation. Five types:
  • PRIMARY KEY
  • UNIQUE
  • NULL/NOT NULL
  • FOREIGN KEY
  • CHECK Note that UNIQUE is really a way of specifying an alternate key. In this slide, the constraints are defining a primary key and an alternate key (aka candidate key). Note that names that are given to the keys: In this case, suffix of PK and AK to identify key variety. Not required, but good practice