A <column constraint> is a constraint that applies to a single column.

Size: px
Start display at page:

Download "A <column constraint> is a constraint that applies to a single column."

Transcription

1 Lab 7 Aim: Creating Simple tables in SQL Basic Syntax for create table command is given below: CREATE TABLE <table_name> ( <column_name> <data_type> [DEFAULT <expression>] [<column_constraint>], {<column_name> <data_type> [DEFAULT <expression>] [column_constraint>],} [<table_constraints>] ); The parts enclosed in square brackets ([ ]) are optional. Curly braces ({ } )indicate that the enclosed expression can be repeated zero or many times. Angle brackets (< >) indicate that these are meta symbols that would be replaced by actual symbols of the language. Underlined paranthesis are part of the command. (Of course you do not underline them when you write the actual command in SQL*Plus J ) <column_name> should be replaced by actual column (attribute) names of the table. <data_type> can be one of the following: VARCHAR2(size): Variable length character string up to maximum length size CHAR(size): Fixed length character string of length size NUMBER: Floating point number with a precision of 38 significant digits NUMBER(p,s): Number with a maximum precision p and maximum scale s. Scale is the number of digits to the right of the decimal point. DATE: Date and time values between January 1, 4712 B.C. and December 31, 4712 A.C. LONG: Variable Length charcater values up to 2GB. Only one LONG column is allowed per table RAW or LONG RAW: Equivalent to VARCHAR2 and LONG, respectively, but used to store byte oriented or binary data Table and column constraints are formed using one of the following constraint keywords. <constraint_type> NOT NULL: Specifies that a given column cannot contain any NULL values UNIQUE: Specifies that values in a column or a combination of columns must be all unique. A unique index (that has the same name as the unique constraint) is automatically created for UNIQUE column(s). PRIMARY KEY: Specifies that a column or a combination of columns must be all UNIQUE and NOT NULL. There can be only one PRIMARY KEY in each table. A UNIQUE index (whose name is the same as the constraint name) is created for the PRIMARY KEY. FOREIGN KEY REFERENCES: Establishes and enforces foreign key relationship between the specified column(s) and the referenced column(s) CHECK: Specifies that the given condition should always hold. A <column constraint> is a constraint that applies to a single column. <column_constraint> for PRIMARY KEY, UNIQUE and NOT NULL constraints is of the following form: [CONSTRAINT <constraint_name>] <constraint_type>

2 You do not have to give a name to each constraint. But it is a good practice to name all constraints, because constraint names are used the error messages and giving rational names to constraints makes it easier to understand the messages. <constraint_name> can be any name you choose. ORACLE suggests using the following combination tablename_columnname_abbreviation where abbreviation is pk for PRIMARY KEY, uk for UNIQUE KEY, fk for FOREIGN KEY, ck for CHECK CONSTRAINT and nn for NOT NULL CONSTRAINT. The form of a Foreign Key constraint that applies to a single column is [CONSTRAINT <constraint_name> ] REFERENCES < referenced_table> ( <referenced_attribute>) <referenced_table> is the parent table and the <referenced_attribute> is the primary or unique key of the parent table. CHECK constraint has the following form [CONSTRAINT <constraint_name> ] CHECK (<condition>) where, <condition> is a condition that should be satisfied for the column. Table constraints are the constraints that apply to more than one column. Table constraints are more general than the column constraints, therefore column constraints can be specified as table constraints. The form of PRIMARY KEY, UNIQUE and NOT NULL table constraints is given below: [CONSTRAINT <constraint_name>] <constraint> (<column_list>) The form for FOREIGN KEY table constraint is : [CONSTRAINT <constraint_name> ] FOREIGN KEY (<foreign_key_columns>) REFERENCES <referenced_table> ( <referenced_attribute>) The form for CHECK constraint at table level is the same as the column level CHECK constraint. Example 1: Create a table for keeping information about your friends. SQL> CREATE TABLE friend 2 (friendno NUMBER(2) CONSTRAINT friend_friendno_pk PRIMARY KEY, 3 name VARCHAR2(25) CONSTRAINT friend_name_nn NOT NULL, 4 phone VARCHAR2(15), 5 city VARCHAR2(10) DEFAULT 'GIRNE'); Table created. Column declarations are separated by a comma. If constraint names (shown in italic in the example) are not specified, ORACLE will assign an alphanumeric identifier (like SYS_C ) for each one of such constraints and use this identifier when it generates error messages: An example error message is given below:

3 ORA-00001: unique constraint (USER50.SYS_C ) violated In line 5 of the above command a default value is specified for the city. This means that if the city value is omitted in an insert statement by default it will be 'GIRNE'. If you want to assign NOT NULL to city, you have to do this explicitly! Example 2 : Consider the following command that creates the s_dept table SQL>CREATE TABLE s_dept 2 ( id NUMBER(7) 6 CONSTRAINT s_dept_id_pk PRIMARY KEY (id), 3 name VARCHAR2(25) CONSTRAINT s_dept_name_nn NOT NULL, 4 region_id NUMBER(7) 5 CONSTRAINT s_dept_region_id_fk REFERENCES s_region(id), 6 CONSTRAINT s_dept_name_region_id_uk UNIQUE (name, region_id)); In the above command, on line 5, you see a foreign key constraint declaration. This constraint forces the region_id column to take only the values that are stored in the id column of the s_region. The table that contains the foreign key is called the child table and the table that contains the referenced column is called the parent table. In this case s_dept is the child and s_region is the parent. You have to make sure that the referenced column (or columns) in the parent table have UNIQUE constraint. (Remember: PRIMARY KEY is UNIQUE and NOT NULL!!!) The table constraint on line 6, ensures that the combination of the values for name and region_id of a department will be unique in the whole table. ALTERING AN EXISTING TABLE Another command that you might find useful when creating a table is the ALTER TABLE command. Modifications allowed without any restrictions include: --Adding a new column to the table. --Deleting a foreign key constraint from a table. --Deleting a primary key constraint from a table, which also removes any references to it from other tables in the database with CASCADE clause. --Increasing the size of a column. For example, VARCHAR2(15) can be changes to VARCHAR2(20). --Renaming columns. --Renaming constraints. Modifications allowed with restrictions include: --Adding a foreign key constraint is allowed only if the current values are null or exist in the references table's primary key. --Adding a primary key constraint is allowed if the current values are not null and are unique. --Column size may be decreased if existing data can be stored with the new column width. --Adding a unique constraint is possible if the current data values are unique. --Adding a check constraint is possible if the current data values comply with the new constraint. --Adding a default value is possible if there is no data in the column. Modifications not allowed include:

4 --Changing a column's name. --Changing a constraint's name. The format for the ALTER TABLE command to add a new column is given below ADD columnname datatpe; To modify a column, you use the ALTER TABLE command with the modify clause. Column modification includes changes to columns data type, size, default value and NOT NULL column constraint. The format is given below: MODIFY ( <column_name> <datatype> [DEFAULT <expression> ] [NOT NULL] {, <column_name> <datatype> [DEFAULT <expression> ] [NOT NULL]} ); You can increase the width or precision of a column. You can decrease width of columns or change data type of a column only if the column contains no data. A change in the default value affects only the subsequent changes. You can add a NOT NULL constraint only if the column contains no NULL values. Example 3: Add a new column to the friend table SQL> ALTER TABLE friend 2 ADD ( bday date); Example 4: Increase the size of the name field of the friend table to 5o characters. SQL> ALTER TABLE friend 2 MODIFY ( name VARCHAR2(50) ); The format for the ALTER TABLE command to add a new constraint is given below ADD [CONSTRAINT <constraint_name> ] <constraint_type> (<column_list>); where column_list is replaced by the list f the columns that the constraints applies to. Any constraint except for NOT NULL CONSTRAINT can be added using this command. NOT NULL constraint is added using the MODIFY clause of the ALTER TABLE command. Example 5: Add a UNIQUE constraint on the combination of the city and name attributes of the friend table of example 1. SQL > ALTER TABLE friend 2 ADD CONSTRAINT friend_name_city_uk UNIQUE(city,name); To drop a column of a given table the ALTER TABLE command is used as given below: DROP COLUMN column_name; To drop a constraint of a given table the ALTER TABLE command is used as given below:

5 DROP CONSTRAINT <constraint_name> [CASCADE] ; constraint_name is the name given in the CREATE TABLE command. If you do not remember the <constraint_name>, you can check the data dictionary views called USER_CONSTRAINTS and USER_CONS_COLUMNS. CASCADE keyword causes all dependent constraints to be dropped as well. If there are any other constraints that depend on the constraint that you are trying to drop, DBMS engine does not let you drop the constraint. For example you cannot drop a primary key constraint if there are any foreign key constraints referring to it, unless you use the keyword CASCADE. The primary key constraint and unique constraints can also be dropped using the following drop constraint clause: DROP PRIMARY KEY UNIQUE(<column_list>) CONSTRAINT constraintname [CASCADE] ; Example 6: a) SQL > ALTER TABLE friend 2 DROP PRIMARY KEY CASCADE; b) Drop the constraint you added in example 3. SQL > ALTER TABLE friend 2 DROP CONSTRAINT friend_name_city_uk; You can also enable or disable a constraint without dropping or recreating them. The format is: DISABLE ENABLE CONSTRAINT <constraint_name> [CASCADE]; A constraint is NOT enabled if there are any values in the table that violate it. If you need to add a new column to a table you can use the ALTER TABLE command with the ADD clause as follows ADD (<column_name> <data_type> [DEAFULT <expression>][<column_constraint>] {,<column_name> <data_type> [DEAFULT <expression>] [ <column_constraint>] }); You can add as many columns as you like in one ALTER TABLE statement. In SQL, if you want to delete a table, you DROP it. This is true for all schema objects. Anything created by the CREATE command is deleted by the DROP command. The format of the DROP table command is given below: DROP TABLE <table_name> [CASCADE CONSTRAINTS];

6 This will cause the table to be dropped. The CASCADE CONSTRAINTS clause is important if the table, you are trying to drop, is referenced by other tables. If you do NOT supply this clause in the DROP TABLE statement and if the table is referenced by other tables, DBMS engine will NOT drop the table. Example 7 : Drop the friend table. SQL > DROP TABLE friend; You can rename a table provided you are the owner of the table. The general syntax is: RENAME oldtablename TO newtablename; Example 8: Change the name of the friend table to myfriends. RENAME friend to myfriends; Truncating a table is removing all records/rows from the table. The structure of the table, however, stays intact. You must be the owner of the table with the DELETE TABLE privilege to truncate a table. The SQL language has a DELETE statement that can be used to remove one or more (or all) rows from a table, and it is reversible as long as it is not committed. The TRUNCATE statement, on the other hand, is not reversible. The syntax is: TRUNCATE TABLE tablename; Exercise Movies(movieid, title, director_name, rating, producing_studio, format) Rented(customerid, movieid) Customer(customerid, name, address, age, balance) These tables have obvious meanings. Movies is the set of movies owned by the video store. Each tuple contains the title of the movie, the name of the director, the rating (e.g., "PG" or "PG-13"), the studio that produced the movie (e.g., "Miramax"), and the format of the movie (e.g., "Video Cassette" or "DVD"). The attribute "movieid" is meant to be the key (presumably assigned by the store). Notice that a given movie that is available in many formats will have different movieids, one for each format. An alternate key for this relation are the two attributes (title, format). In other words, the title and format functionally determine all the other attributes in Movies, such as the movieid, director's name, rating, and studio. Do not worry about the fact that "year" is not a part of the key or the relation. Customer is a table that identifies the customers of the store, their name, dob, address (e.g., "123 Main Street, Blacksburg"), and balance (e.g., "$30" or "-$15"). Rented is a history of who has rented what in the past

3ISY402 DATABASE SYSTEMS

3ISY402 DATABASE SYSTEMS 3ISY402 DATABASE SYSTEMS - SQL: Data Definition 1 Leena Gulabivala Material from essential text: T CONNOLLY & C BEGG. Database Systems A Practical Approach to Design, Implementation and Management, 4th

More information

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Database Foundations. 6-3 Data Definition Language (DDL) Copyright 2015, Oracle and/or its affiliates. All rights reserved. Database Foundations 6-3 Roadmap You are here Introduction to Oracle Application Express Structured Query Language (SQL) Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control

More information

Data Definition Language (DDL)

Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 6 Data Definition Language (DDL) Eng. Mohammed Alokshiya November 11, 2014 Database Keys A key

More information

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Categorize the main database

More information

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables Copyright 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Categorize the main database

More information

CHAPTER4 CONSTRAINTS

CHAPTER4 CONSTRAINTS CHAPTER4 CONSTRAINTS LEARNING OBJECTIVES After completing this chapter, you should be able to do the following: Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN KEY,

More information

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 IS220 : Database Fundamentals College of Computer and Information Sciences - Information Systems Dept. Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Ref. Chapter6 Prepared by L.

More information

Lab # 4. Data Definition Language (DDL)

Lab # 4. Data Definition Language (DDL) Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Lab # 4 Data Definition Language (DDL) Eng. Haneen El-Masry November, 2014 2 Objective To be familiar with

More information

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2 Ref. Chapter6 Prepared by L. Nouf Almujally & Aisha AlArfaj& L.Fatima Alhayan Colleg Comp Informa Scien Informa Syst D 1 IS220 : Database

More information

The Structured Query Language Get Started

The Structured Query Language Get Started The Structured Query Language Get Started Himadri Barman 0. Prerequisites: A database is an organized collection of related data that can easily be retrieved and used. By data, we mean known facts that

More information

Creating and Managing Tables Schedule: Timing Topic

Creating and Managing Tables Schedule: Timing Topic 9 Creating and Managing Tables Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice 50 minutes Total Objectives After completing this lesson, you should be able to do the following: Describe the

More information

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH Private Institute of Aga 2018 NETWORK DATABASE LECTURER NIYAZ M. SALIH Data Definition Language (DDL): String data Types: Data Types CHAR(size) NCHAR(size) VARCHAR2(size) Description A fixed-length character

More information

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama The Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4113: Database Lab Lab # 2 Data Definition Language (DDL) Eng. Alaa O Shama October, 2015 Objective To be familiar

More information

Lecture 07. Spring 2018 Borough of Manhattan Community College

Lecture 07. Spring 2018 Borough of Manhattan Community College Lecture 07 Spring 2018 Borough of Manhattan Community College 1 SQL Identifiers SQL identifiers are used to identify objects in the database, such as table names, view names, and columns. The ISO standard

More information

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved.

Using DDL Statements to Create and Manage Tables. Copyright 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables Objectives After completing this lesson, you should be able to do the following: Categorize the main database objects Review the table structure List the

More information

4 Schema Definition with SQL / DDL (II)

4 Schema Definition with SQL / DDL (II) 4 Schema Definition with SQL / DDL (II) 4.3 SQL/DDL Constraints 4.3.1 Attribute and simple table constraints 4.3.2 Enforcing cardinality constraints and foreign keys 4.3.3 Deferred constraints 4.3.4 Assertions

More information

Unit 1 - Chapter 4,5

Unit 1 - Chapter 4,5 Unit 1 - Chapter 4,5 CREATE DATABASE DatabaseName; SHOW DATABASES; USE DatabaseName; DROP DATABASE DatabaseName; CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype,... columnn

More information

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1 SQL Fundamentals Chapter 3 Class 03: SQL Fundamentals 1 Class 03: SQL Fundamentals 2 SQL SQL (Structured Query Language): A language that is used in relational databases to build and query tables. Earlier

More information

STRUCTURED QUERY LANGUAGE (SQL)

STRUCTURED QUERY LANGUAGE (SQL) 1 SQL STRUCTURED QUERY LANGUAGE (SQL) The first questions to ask are what is SQL and how do you use it with databases? SQL has 3 main roles: Creating a database and defining its structure Querying the

More information

Database Programming - Section 10. Instructor Guide

Database Programming - Section 10. Instructor Guide Database Programming - Section 10 Instructor Guide Table of Contents...1 Lesson 1 - Defining NOT NULL and UNIQUE Constraints...1 What Will I Learn?...2 Why Learn It?...3...4 Try It / Solve It...13 Lesson

More information

Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -1: Transactions and concurrency in ORACLE.

Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -1: Transactions and concurrency in ORACLE. Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -2: More SQL queries Week -1: Transactions and concurrency in ORACLE. But don t forget to work on

More information

Relational Database Language

Relational Database Language DATA BASE MANAGEMENT SYSTEMS Unit IV Relational Database Language: Data definition in SQL, Queries in SQL, Insert, Delete and Update Statements in SQL, Views in SQL, Specifying General Constraints as Assertions,

More information

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity SQL language: basics Creating a table Modifying table structure Deleting a table The data dictionary Data integrity 2013 Politecnico di Torino 1 Creating a table Creating a table (1/3) The following SQL

More information

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands

More information

INTRODUCTION TO DATABASE

INTRODUCTION TO DATABASE 1 INTRODUCTION TO DATABASE DATA: Data is a collection of raw facts and figures and is represented in alphabets, digits and special characters format. It is not significant to a business. Data are atomic

More information

Full file at

Full file at ch2 True/False Indicate whether the statement is true or false. 1. The SQL command to create a database table is an example of DML. 2. A user schema contains all database objects created by a user. 3.

More information

SQL: DDL. John Ortiz Cs.utsa.edu

SQL: DDL. John Ortiz Cs.utsa.edu SQL: DDL John Ortiz Cs.utsa.edu SQL Data Definition Language Used by DBA or Designer to specify schema A set of statements used to define and to change the definition of tables, columns, data types, constraints,

More information

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1 COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE

More information

Tutorial 1 Database: Introductory Topics

Tutorial 1 Database: Introductory Topics Tutorial 1 Database: Introductory Topics Theory Reference: Rob, P. & Coronel, C. Database Systems: Design, Implementation & Management, 6th Edition, 2004, Chapter 1. Review Questions 2 7, 9 10. Problems

More information

COMP102: Introduction to Databases, 5 & 6

COMP102: Introduction to Databases, 5 & 6 COMP102: Introduction to Databases, 5 & 6 Dr Muhammad Sulaiman Khan Department of Computer Science University of Liverpool U.K. 8/11 February, 2011 Introduction: SQL, part 2 Specific topics for today:

More information

Chapter-14 SQL COMMANDS

Chapter-14 SQL COMMANDS Chapter-14 SQL COMMANDS What is SQL? Structured Query Language and it helps to make practice on SQL commands which provides immediate results. SQL is Structured Query Language, which is a computer language

More information

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

ITCertMaster.   Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way! ITCertMaster Safe, simple and fast. 100% Pass guarantee! http://www.itcertmaster.com Exam : 1z0-007 Title : Introduction to Oracle9i: SQL Vendor : Oracle Version : DEMO Get Latest & Valid 1Z0-007 Exam's

More information

CSC Web Programming. Introduction to SQL

CSC Web Programming. Introduction to SQL CSC 242 - Web Programming Introduction to SQL SQL Statements Data Definition Language CREATE ALTER DROP Data Manipulation Language INSERT UPDATE DELETE Data Query Language SELECT SQL statements end with

More information

Indexes (continued) Customer table with record numbers. Source: Concepts of Database Management

Indexes (continued) Customer table with record numbers. Source: Concepts of Database Management 12 Advanced Topics Objectives Use indexes to improve database performance Examine the security features of a DBMS Discuss entity, referential, and legal-values integrity Make changes to the structure of

More information

DATA CONSTRAINT. Prepared By: Dr. Vipul Vekariya

DATA CONSTRAINT. Prepared By: Dr. Vipul Vekariya DATA CONSTRAINT Prepared By: Dr. Vipul Vekariya What is constraint? Constraints enforce rules at the table level. Constraints prevent the deletion of a table if there are dependencies. There are two types

More information

SQL DATA MANIPULATION. Prepared By: Dr. Vipul Vekariya.

SQL DATA MANIPULATION. Prepared By: Dr. Vipul Vekariya. SQL DATA MANIPULATION Prepared By: Dr. Vipul Vekariya. SQL DATA MANIPULATION SQL DATA TYPES CREATE CLAUSE SELECTCLAUSE ORDERED BY CLAUSE AS CLAUSE Basic Data Types of SQL CHAR NUMERIC VARCHAR/VARCHAR 2

More information

Lecture 6 Structured Query Language (SQL)

Lecture 6 Structured Query Language (SQL) ITM661 Database Systems Lecture 6 Structured Query Language (SQL) (Data Definition) T. Connolly, and C. Begg, Database Systems: A Practical Approach to Design, Implementation, and Management, 5th edition,

More information

Creating SQL Tables and using Data Types

Creating SQL Tables and using Data Types Creating SQL Tables and using Data Types Aims: To learn how to create tables in Oracle SQL, and how to use Oracle SQL data types in the creation of these tables. Outline of Session: Given a simple database

More information

3.2.4 Enforcing constraints

3.2.4 Enforcing constraints 3.2.4 Enforcing constraints Constraints SQL definition of the schema Up to now: primary Key, foreign key, NOT NULL Different kinds of integrity constraints value constraints on attributes cardinalities

More information

MTAT Introduction to Databases

MTAT Introduction to Databases MTAT.03.105 Introduction to Databases Lecture #3 Data Types, Default values, Constraints Ljubov Jaanuska (ljubov.jaanuska@ut.ee) Lecture 1. Summary SQL stands for Structured Query Language SQL is a standard

More information

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton Creating Tables, Defining Constraints Rose-Hulman Institute of Technology Curt Clifton Outline Data Types Creating and Altering Tables Constraints Primary and Foreign Key Constraints Row and Tuple Checks

More information

SQL functions fit into two broad categories: Data definition language Data manipulation language

SQL functions fit into two broad categories: Data definition language Data manipulation language Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my

More information

SQL Data Definition: Table Creation

SQL Data Definition: Table Creation SQL Data Definition: Table Creation ISYS 464 Spring 2002 Topic 11 Student Course Database Student (Student Number, Student Name, Major) Course (Course Number, Course Name, Day, Time) Student Course (Student

More information

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng.

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng. Ahmed Abumarasa Database Lab Lab 2 Database Table Introduction: The previous

More information

1) Introduction to SQL

1) Introduction to SQL 1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform

More information

SQL DATA MANIPULATION. Prepared By: Vipul Vekariya M.E( Computer) Gardi College Of Eng. & Tech. Rajkot.

SQL DATA MANIPULATION. Prepared By: Vipul Vekariya M.E( Computer) Gardi College Of Eng. & Tech. Rajkot. SQL DATA MANIPULATION Prepared By: Vipul Vekariya M.E( Computer) Gardi College Of Eng. & Tech. Rajkot. SQL DATA MANIPULATION SQL DATA TYPES CREATE CLAUSE SELECTCLAUSE ORDERED BY CLAUSE AS CLAUSE Basic

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

EDB Postgres Hadoop Data Adapter Guide

EDB Postgres Hadoop Data Adapter Guide EDB Postgres Hadoop Data Adapter Guide September 27, 2016 by EnterpriseDB Corporation EnterpriseDB Corporation, 34 Crosby Drive Suite 100, Bedford, MA 01730, USA T +1 781 357 3390 F +1 978 589 5701 E info@enterprisedb.com

More information

Data Base Lab. The Microsoft SQL Server Management Studio Part-3- By :Eng.Alaa I.Haniy.

Data Base Lab. The Microsoft SQL Server Management Studio Part-3- By :Eng.Alaa I.Haniy. Data Base Lab Islamic University Gaza Engineering Faculty Computer Department Lab -5- The Microsoft SQL Server Management Studio Part-3- By :Eng.Alaa I.Haniy. SQL Constraints Constraints are used to limit

More information

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University SQL - Subqueries and Chapter 3.4 V4.0 Copyright @ Napier University Schema Subqueries Subquery one SELECT statement inside another Used in the WHERE clause Subqueries can return many rows. Subqueries can

More information

Structured Query Language. ALTERing and SELECTing

Structured Query Language. ALTERing and SELECTing Structured Query Language ALTERing and SELECTing Altering the table structure SQL: ALTER Table SQL: Alter Table The ALTER TABLE command allows you to add, modify, or drop a column from an existing table.

More information

Oracle Database 10g: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Student Guide Volume 2. D17108GC30 Edition 3.0 January 2009 D57871

Oracle Database 10g: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Student Guide Volume 2. D17108GC30 Edition 3.0 January 2009 D57871 D17108GC30 Edition 3.0 January 2009 D57871 Oracle Database 10g: SQL Fundamentals I Student Guide Volume 2 Authors Salome Clement Chaitanya Koratamaddi Nancy Greenberg Technical Contributors and Reviewers

More information

다양한예제로쉽게배우는 오라클 SQL 과 PL/SQL 서진수저

다양한예제로쉽게배우는 오라클 SQL 과 PL/SQL 서진수저 다양한예제로쉽게배우는 오라클 SQL 과 PL/SQL 서진수저 8 장제약조건을배웁니다 1 1. 제약조건의종류 조건이름 의 미 NOT NULL 이조건이설정된컬럼에는 NULL 값이입력되지못합니다. UNIQUE 이조건이설정된컬럼에는중복된값이입력되지못합니다. PRIMARY KEY 이조건은 NOT NULL + UNIQUE 의의미를가지며테이블내에서데이터들끼리의유일성을보장하는컬럼에설정할수있으며테이블당

More information

CSC 453 Database Technologies. Tanu Malik DePaul University

CSC 453 Database Technologies. Tanu Malik DePaul University CSC 453 Database Technologies Tanu Malik DePaul University A Data Model A notation for describing data or information. Consists of mostly 3 parts: Structure of the data Data structures and relationships

More information

Mahathma Gandhi University

Mahathma Gandhi University Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed

More information

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language Information Systems Engineering SQL Structured Query Language DDL Data Definition (sub)language 1 SQL Standard Language for the Definition, Querying and Manipulation of Relational Databases on DBMSs Its

More information

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com ORACLE VIEWS ORACLE VIEWS Techgoeasy.com 1 Oracle VIEWS WHAT IS ORACLE VIEWS? -A view is a representation of data from one or more tables or views. -A view is a named and validated SQL query which is stored

More information

Chapter 1 SQL and Data

Chapter 1 SQL and Data Chapter 1 SQL and Data What is SQL? Structured Query Language An industry-standard language used to access & manipulate data stored in a relational database E. F. Codd, 1970 s IBM 2 What is Oracle? A relational

More information

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database. SQL*Plus SQL*Plus is an application that recognizes & executes SQL commands &

More information

IT360: Applied Database Systems. SQL: Structured Query Language DDL and DML (w/o SELECT) (Chapter 7 in Kroenke) SQL: Data Definition Language

IT360: Applied Database Systems. SQL: Structured Query Language DDL and DML (w/o SELECT) (Chapter 7 in Kroenke) SQL: Data Definition Language IT360: Applied Database Systems SQL: Structured Query Language DDL and DML (w/o SELECT) (Chapter 7 in Kroenke) 1 Goals SQL: Data Definition Language CREATE ALTER DROP SQL: Data Manipulation Language INSERT

More information

DB Creation with SQL DDL

DB Creation with SQL DDL DB Creation with SQL DDL Outline SQL Concepts Data Types Schema/Table/View Creation Transactions and Access Control Objectives of SQL Ideally, database language should allow user to: create the database

More information

Unit 7: Database Development (Basic)

Unit 7: Database Development (Basic) Unit 7: Database Development (Basic) CONTENTS Unit 7: Database Development (Basic) SESSION 1: DATABASE CONCEPTS...240 SESSION 2: DATA STORAGE...243 SESSION 3: MANIPULATING DATA...248 SESSION 4: CREATING

More information

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210 SQL: Concepts Todd Bacastow IST 210: Organization of Data 2/17/2004 1 Design questions How many entities are there? What are the major entities? What are the attributes of each entity? Is there a unique

More information

Physical Design of Relational Databases

Physical Design of Relational Databases Physical Design of Relational Databases Chapter 8 Class 06: Physical Design of Relational Databases 1 Physical Database Design After completion of logical database design, the next phase is the design

More information

MySQL Introduction. By Prof. B.A.Khivsara

MySQL Introduction. By Prof. B.A.Khivsara MySQL Introduction By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and not for commercial use. Outline Design

More information

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) SQL language Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c) 2011-2016 SQL - Structured Query Language SQL is a computer language for communicating with DBSM Nonprocedural (declarative) language What

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

Step 0 How to begin and what you need to do before you start?

Step 0 How to begin and what you need to do before you start? Written and cooked by Janusz R. Getta, School of Computing and Information Technology, University of Wollongong Building 3, room 2120, ext 4339, jrg@uow.edu.au, http://www.uow.edu.au/ jrg ËÁ̽½ Ø Å Ò Ñ

More information

Standard Query Language. SQL: Data Definition Transparencies

Standard Query Language. SQL: Data Definition Transparencies Standard Query Language SQL: Data Definition Transparencies Chapter 6 - Objectives Data types supported by SQL standard. Purpose of integrity enhancement feature of SQL. How to define integrity constraints

More information

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

Chapter # 7 Introduction to Structured Query Language (SQL) Part I Chapter # 7 Introduction to Structured Query Language (SQL) Part I Introduction to SQL SQL functions fit into two broad categories: Data definition language Data manipulation language Basic command set

More information

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language

More information

Difficult I.Q on Databases, asked to SCTPL level 2 students 2015

Difficult I.Q on Databases, asked to SCTPL level 2 students 2015 Do you know the basic memory structures associated with any Oracle Database. (W.r.t 10g / 11g / 12c)? The basic memory structures associated with Oracle Database include: System Global Area (SGA) The SGA

More information

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions

RDBMS-Day3. SQL Basic DDL statements DML statements Aggregate functions RDBMS-Day3 SQL Basic DDL statements DML statements Aggregate functions SQL SQL is used to make a request to retrieve data from a Database. The DBMS processes the SQL request, retrieves the requested data

More information

INTRODUCTION TO MYSQL MySQL : It is an Open Source RDBMS Software that uses Structured Query Language. It is available free of cost. Key Features of MySQL : MySQL Data Types: 1. High Speed. 2. Ease of

More information

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key

3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key Unit 3: Types of Keys & Data Integrity 3.1. Keys: Super Key, Candidate Key, Primary Key, Alternate Key, Foreign Key Different Types of SQL Keys A key is a single or combination of multiple fields in a

More information

Transforming ER to Relational Schema

Transforming ER to Relational Schema Transforming ER to Relational Schema Transformation of ER Diagrams to Relational Schema ER Diagrams Entities (Strong, Weak) Relationships Attributes (Multivalued, Derived,..) Generalization Relational

More information

The Relational Model

The Relational Model The Relational Model What is the Relational Model Relations Domain Constraints SQL Integrity Constraints Translating an ER diagram to the Relational Model and SQL Views A relational database consists

More information

Lecture 5 Data Definition Language (DDL)

Lecture 5 Data Definition Language (DDL) ITM-661 ระบบฐานข อม ล (Database system) Walailak - 2013 Lecture 5 Data Definition Language (DDL) Walailak University T. Connolly, and C. Begg, Database Systems: A Practical Approach to Design, Implementation,

More information

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects ASSIGNMENT NO 2 Title: Design and Develop SQL DDL statements which demonstrate the use of SQL objects such as Table, View, Index, Sequence, Synonym Objectives: To understand and demonstrate DDL statements

More information

From theory to practice. Designing Tables for an Oracle Database System. Sqlplus. Sqlplus. Technicalities. Add the following to your.

From theory to practice. Designing Tables for an Oracle Database System. Sqlplus. Sqlplus. Technicalities. Add the following to your. From theory to practice Designing Tables for an Oracle Database System The Entity-Relationship model: a convenient way of representing the world. The Relational model: a model for organizing data using

More information

G64DBS Database Systems. Lecture 6 More SQL Data. Creating Relations. Column Constraints. Last Lecture s Question

G64DBS Database Systems. Lecture 6 More SQL Data. Creating Relations. Column Constraints. Last Lecture s Question G6DBS Database Systems Lecture 6 More SQL Data Tim Brailsford Creating Relations From last lecture.. CREATE TABLE CREATE TABLE ( , ) Column definitions are made

More information

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... ) 2.9 Table Creation CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... ) CREATE TABLE Addresses ( id INTEGER, name VARCHAR(20), zipcode CHAR(5), city VARCHAR(20), dob DATE ) A list of valid

More information

Designing Tables for an Oracle Database System. From theory to practice

Designing Tables for an Oracle Database System. From theory to practice Designing Tables for an Oracle Database System Database Course, Fall 2004 From theory to practice The Entity- Relationship model: a convenient way of representing the world. The Relational model: a model

More information

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas SQL SQL Functionality stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original

More information

15CSL58: DATABASE MANAGEMENT LABORATORY

15CSL58: DATABASE MANAGEMENT LABORATORY 15CSL58: DATABASE MANAGEMENT LABORATORY Subject Code: 15CSL58 I.A. Marks: 20 Hours/Week: L(1)+P(2) Exam Hours: 03 Total Hours: 40 Exam Marks: 80 Course objectives: This course will enable students to Foundation

More information

Chapter 14 Data Dictionary and Scripting

Chapter 14 Data Dictionary and Scripting Chapter 14 Data Dictionary and Scripting Tables in the Oracle Database User Tables Collection of tables to store data Data Dictionary Tables Collection of tables created and maintained by Oracle server

More information

Intermediate SQL ( )

Intermediate SQL ( ) CSL 451 Introduction to Database Systems Intermediate SQL (4.1-4.4) Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Summary Join

More information

CS2300: File Structures and Introduction to Database Systems

CS2300: File Structures and Introduction to Database Systems CS2300: File Structures and Introduction to Database Systems Lecture 14: SQL Doug McGeehan From Theory to Practice The Entity-Relationship Model: a convenient way of representing the world. The Relational

More information

Oracle Tables TECHGOEASY.COM

Oracle Tables TECHGOEASY.COM Oracle Tables TECHGOEASY.COM 1 Oracle Tables WHAT IS ORACLE DATABASE TABLE? -Tables are the basic unit of data storage in an Oracle Database. Data is stored in rows and columns. -A table holds all the

More information

To understand the concept of candidate and primary keys and their application in table creation.

To understand the concept of candidate and primary keys and their application in table creation. CM0719: Database Modelling Seminar 5 (b): Candidate and Primary Keys Exercise Aims: To understand the concept of candidate and primary keys and their application in table creation. Outline of Activity:

More information

Downloaded from

Downloaded from Unit-III DATABASES MANAGEMENT SYSTEM AND SQL DBMS & Structured Query Language Chapter: 07 Basic Database concepts Data : Raw facts and figures which are useful to an organization. We cannot take decisions

More information

Unit 27 Web Server Scripting Extended Diploma in ICT

Unit 27 Web Server Scripting Extended Diploma in ICT Unit 27 Web Server Scripting Extended Diploma in ICT Dynamic Web pages Having created a few web pages with dynamic content (Browser information) we now need to create dynamic pages with information from

More information

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Data Modelling and Databases. Exercise Session 7: Integrity Constraints Data Modelling and Databases Exercise Session 7: Integrity Constraints 1 Database Design Textual Description Complete Design ER Diagram Relational Schema Conceptual Modeling Logical Modeling Physical Modeling

More information

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo Relational Model CSE462 Database Concepts Demian Lessa Department of Computer Science and Engineering State University of New York, Buffalo January 21 24, 2011 Next... 1 Relational Model Lessa Relational

More information

Exact Numeric Data Types

Exact Numeric Data Types SQL Server Notes for FYP SQL data type is an attribute that specifies type of data of any object. Each column, variable and expression has related data type in SQL. You would use these data types while

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2 CMPT 354 Constraints Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers John Edgar 2 firstname type balance city customerid lastname accnumber rate branchname phone

More information

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul 1 EGCI 321: Database Systems Dr. Tanasanee Phienthrakul 2 Chapter 10 Data Definition Language (DDL) 3 Basic SQL SQL language Considered one of the major reasons for the commercial success of relational

More information

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data. Managing Data Data storage tool must provide the following features: Data definition (data structuring) Data entry (to add new data) Data editing (to change existing data) Querying (a means of extracting

More information

CIS Slightly-different version of Week 10 Lab, also intro to SQL UPDATE and DELETE, and more

CIS Slightly-different version of Week 10 Lab, also intro to SQL UPDATE and DELETE, and more CIS 315 - Week 10 Lab Exercise p. 1 Sources: CIS 315 - Slightly-different version of Week 10 Lab, 10-27-09 more SELECT operations: UNION, INTERSECT, and MINUS, also intro to SQL UPDATE and DELETE, and

More information