Download presentation
Presentation is loading. Please wait.
Published byChristina Reeves Modified over 8 years ago
1
Physical Model Lecture 11
3
Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access
4
Structured Query Language (SQL) SQL (sequel) is used on a most RDBMS systems and ORDBMS (Oracle, PostGIS, IBM DB2, MySQL and SQL Server) The first version of SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL
5
SQL The SQL language is sub-divided into several language elements, including: – Data Definition Language (DDL) – Data Manipulation Language and Transaction Control (DML) – Query Language – Procedural Language PL/SQL and – Data Control Language DCL. (language for DBA)
6
Data Definition Language (DDL) DDL allows the user to define new database objects › Tables › Views › Index and › Other elements The most basic items of DDL are the › CREATE, › ALTER, › RENAME, › TRUNCATE and › DROP statements :
7
Data Definition Language (DDL) CREATE causes an object (a table, for example) to be created within the database. DROP causes an existing object within the database to be deleted, usually irretrievably. TRUNCATE deletes all data from a table (non- standard, but common SQL statement). ALTER statement permits the user to modify an existing object in various ways -- for example, adding a column to an existing table. 7
8
Create table Command CREATE TABLE ([schema.]table column datatype [DEFAULT expr] [column_constraint(s)] [,column datatype [,...]] ) table_constraint table_ref_constraintdatatypecolumn_constraint(s) table_constrainttable_ref_constraint
9
Oracle Data types Numeric Data Types String Data Types Data/Time Data Types Spatial Data Types
10
Oracle Data Types (Numeric) NUMBER (p, q) signed number p digits, q decimals PLS_INTEGERused only in PL/SQL
11
Oracle Data Types (String) CHAR(n) fixed length string, VARCHAR2(n) varying length string, up to n-8 bits NCHAR(n) fixed length string national character set NVARCHAR2(n) varying length string national characterset
12
Oracle Data Types (Date/Time) DATE TIMESTAMP (fractional_seconds_precision)
13
Create a Table CREATE TABLE [GLOBAL TEMPORARY] table_name (column_name data_type [NOT NULL] [UNIQUE][DEFAULT default_option] [CHECK (search_condition)] [,…] [PRIMARY KEY (list_of_columns),] {[UNIQUE (list_of_columns),][,…]} {[FOREIGN KEY {(list_of_foreign_key_columns) REFERENCES parent_table_name[(list_of_candidate_key_columns)]) [] optional, {} one or more, lower case – user supplied names, upper case reserved words, [|] either or, () are part of the syntax.
14
Specifying Primary and Foreign keys Constraints can be added to the table at the time it is created, i.e. the primary key on dnumber and foreign key on mgrssn CREATE TABLE department ( dname VARCHAR2(15) NOT NULL, dnumber INTEGER NOT NULL, mgrssn VARCHAR2 (9) NOT NULL, mgrstartdate DATE, CONSTRAINT department_pk PRIMARY KEY(dnumber), CONSTRAINT fk_department_emp FOREIGN KEY(mgrssn) REFERENCES employee (ssn) );
15
ALTER TABLE COMMAND ALTER TABLE – used to change an existing table definition. This statement can be used to › add a new column › remove an existing column in a table › modify the data type for an existing column › add or remove a constraint. We will add constraints on the employee table using the ALTER TABLE statement
16
ALTER TABLE SYNTAX ALTER TABLE [schema].table_name ADD [COLUMN] column_name ALTER TABLE [schema].table_name ADD constraint_declare ALTER TABLE [schema].table_name DROP [COLUMN] column_name ALTER TABLE [schema].table_name DROP CONSTRAINT constraint_name ALTER TABLE [schema].table_name DROP PRIMARY KEY ALTER TABLE [schema].table_name ALTER [COLUMN] column_name SET default_expr ALTER TABLE [schema].table_name ALTER [COLUMN] column_name DROP DEFAULT
17
Alter Table To add primary key and foreign key constraint to the employee table ALTER TABLE employee ADD CONSTRAINT pk_emp PRIMARY KEY (ssn);
18
DROP TABLE COMMAND To delete complete table use drop command Syntax – DROP TABLE [schema].table_name
19
DROP TABLE COMMAND To delete complete table use drop command Syntax – DROP TABLE [schema].table_name
20
Truncate Command Use to remove all the rows from the table Syntax – TRUNCATE TABLE [schema].table_name
21
Inserting data into a table To add a row of data to a table INSERT INTO VALUES (value1, value2, …valueN) If the value list matches the column list exactly, there is no need to list the column names. If the value list does not match the column list exactly, there is a need to list the column names.
22
Example insert into Expert values (2222221,'Dr. O‘’Meara’,'Orthopaedic');
23
Delete Delete from expert where expert_id = 2222221; This deletes all rows from the expert table that have an expert_id of 2222221. Please note that you can only delete a row if no other row depends on it.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.