Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.

Slides:



Advertisements
Similar presentations
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
Advertisements

Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
Sanjay Goel, School of Business, University at Albany, SUNY 1 SQL- Data Definition Language ITM 692 Sanjay Goel.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Database Management System LICT 3011 Eyad H. Elshami.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 10: Data Definition Language.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Oracle Data Definition Language (DDL)
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Chapter 6 SQL Data Definition Language Chapter 7 in Textbook.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
SQL: DDL John Ortiz Cs.utsa.edu.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Data Definition Language
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Introduction to Database Systems
At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
CS 3630 Database Design and Implementation
Managing Tables, Data Integrity, Constraints by Adrienne Watt
SQL: Schema Definition and Constraints Chapter 6 week 6
ORACLE SQL Developer & SQLPLUS Statements
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
SQL OVERVIEW DEFINING A SCHEMA
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Oracle Data Definition Language (DDL)
SQL-1 Week 8-9.
Database Management System
Session - 6 Sequence - 1 SQL: The Structured Query Language:
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: SAMIA ARSHAD
SQL (Structured Query Language)
Presentation transcript:

Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems

Types of SQL Statements that will be covered: Data Definition Language (DDL): Commands that define a database. E.g. CREATE, ALTER, DROP,...etc. Data manipulation language (DML): Commands that maintain and query a database. E.g. SELECT, INSERT, UPDATE, DELETE

COMPANY Schema Given the following schema for a COMPANY database: EMPLOYEE DEPARTMENT FNAMEMINITLNAMESSNSALARYDNO DNAMEDNUMBERLOCATION

SQL*Plus Open SQL*Plus, enter appropriate name, password, & host string scott psu stddata

CREATE TABLE Structure CREATE TABLE [schema.]TABLENAME ( ColumnName Type [DEFAULT value] [Constraints], [TableConstraints] );

Types CHAR(n): a fixed-length string n characters long (default 1, max 255 character). VARCHAR(n): a variable string up to n character long (max 2000). INT: an integer number. DECIMAL(n,d): a number n digits long including d decimal places. DATE: a valid date YYYY-MM-DD.

COLUMN LEVEL CONSTRAINTS NOT NULL UNIQUE PRIMARY KEY REFRENCES table key Check TABLE LEVEL CONSTRAINTS UNIQUE (Column-list) CONSTRAINT name PRIMARY KEY column_list CONSTRAINT name FOREIGN KEY column-list REFRENCES table column-list CHECK (Condition) ON DELETE CASACADE, ON DELETE SET NULL

Write appropriate SQL DDL statements to declare the COMPANY schema. CREATE TABLE DEPARTMENT ( DNAMEVARCHAR2(20)NOT NULL UNIQUE, DNUMBERNUMBER(2), LOCATIONVARCHAR2(20), CONSTRAINT DEPT_PKEY PRIMARY KEY (DNUMBER)); CREATE TABLE EMPLOYEE ( FNAMEVARCHAR2(15)NOT NULL, MINIT CHAR, LNAMEVARCHAR2(15)NOT NULL, SSNCHAR(9), SALARYNUMBER(10,2)NOT NULL, DNONUMBER(2), CONSTRAINT EMP_PKEY PRIMARY KEY (SSN), CONSTRAINT EMP_FKEY FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNUMBER));

Display the structure of your tables. desc DEPARTMENT desc EMPLOYEE

Tables can be changed using ALTER TABLE

Add the following columns to the EMPLOYEE table:  ADDRESS  SEX ( Only accepts M, F) ALTER TABLE table_name ADD column_name datatype ALTER TABLE EMPLOYEE ADD ( ADDRESS VARCHAR2(30), SEX CHAR(1) CHECK (SEX IN ('M', 'F'))); Add/drop column

Remove column Address from table employee Alter table Employee Drop column address;

Change a column definition Modify ADDRESS so that NULL values are not accepted ALTER TABLE EMPLOYEE MODIFY ADDRESS NOT NULL;

Add/ Drop a constraint Drop Primary key from table employee alter table table_name drop constraint constraint_name; Alter table employee Drop constraint EMP_FKEY Add constraint to table employee alter table table_name add constraint constraint_name; ALTER TABLE employee ADD CONSTRAINT emp_pk Primary Key(SSN) ;

Insert the following tuple into the DEPARTMENT table: DNAME = ‘Project’ DNUMBER = 5 DLOCATION = ‘Houston’ INSERT INTO table_name VALUES (value1, value2, value3,...) INSERT INTO DEPARTMENT VALUES ('Project', 5, 'Houston');

Write an INSERT statement in which each time it is run, the user will be prompted for a new set of values (DEPARTMENT table) INSERT INTO DEPARTMENT VALUES ('&D_NAME', &D_NUMBER, '&D_LOCATION'); Execute the previous statement twice, and insert the following values: D_NAME = Administration D_NUMBER = 4 D_LOCATION = Stafford D_NAME = Headquarters D_NUMBER = 1 D_LOCATION = Bellaire