1 Table Alteration. 2 Altering Tables Table definition can be altered after its creation Adding columns Changing columns’ definition Dropping columns.

Slides:



Advertisements
Similar presentations
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
1 Designing Tables for an Oracle Database System Database Course, Fall 2003.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
1 Reminder We have covered: –Creating tables –Converting ER diagrams to table definitions Today we’ll talk about: –Altering tables –Inserting and deleting.
1 The Oracle Database System Building a Database Database Course The Hebrew University of Jerusalem.
Introduction to Structured Query Language (SQL)
1 Table Alteration. 2 Altering Tables Table definition can be altered after its creation –Adding columns –Changing columns’ definition –Dropping columns.
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
1 Designing Tables for an Oracle Database System Database Course, Fall 2004.
ORACLE Using ORACLE 8 SQL using ORACLE 8 PL/SQL using ORACLE 8.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
ASP.NET Programming with C# and SQL Server First Edition
SQL data definition using Oracle1 SQL Data Definition using Oracle.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
20 Copyright © Oracle Corporation, All rights reserved. Oracle9 i Extensions to DML and DDL Statements.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
The Oracle Database System. Connecting to the Database At the command line prompt, write: sqlplus In the beginning your password.
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.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
SQL LOADER. SQL*Loader (sqlldr ) is the utility to use for high performance data loads. The data can be loaded from any text file and inserted into the.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
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.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
SQL. Internet technologies – Ohad © Database  A database is a collection of data  A database management system (DBMS) is software designed to assist.
1 Designing Tables for a Database System. 2 Where we were, and where we’re going The Entity-Relationship model: Used to model the world The Relational.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Creating and Managing Tables. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns ViewLogically represents subsets.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Chapter 5 Introduction to SQL.
SQL: Schema Definition and Constraints Chapter 6 week 6
SQL and SQL*Plus Interaction
Insert, Update and the rest…
SQL in Oracle.
Introduction to MySQL.
SQL Creating and Managing Tables
Designing Tables for a Database System
ORACLE SQL Developer & SQLPLUS Statements
SQL Creating and Managing Tables
SQL Creating and Managing Tables
Using SQL*Loader The SQL*Loader command needs to be run from a DOS window or NT. The SQL*Loader uses the following three files: control file: contains.
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Using SQL*Plus.
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Including Constraints
Presentation transcript:

1 Table Alteration

2 Altering Tables Table definition can be altered after its creation Adding columns Changing columns’ definition Dropping columns Adding constraints And more… Use the reserved word ALTER

3 Altering Tables (continues) Adding a column: ALTER TABLE Employee ADD ( Mname VARCHAR2(20), Birthday DATE ); Changing columns’ definition: ALTER TABLE Emplyee Modify ( Mname VARCHAR2(10) ); Cannot be NOT NULL unless the table is empty

4 Altering Tables (continues) Dropping columns: ALTER TABLE Employee DROP COLUMN Mname; Dropping multiple columns: ALTER TABLE Employee DROP (Mname, Birthday); Adding constraints: ALTER TABLE Department ADD( FOREIGN KEY (ManagerId) REFERENCES Employee(SSN));

5 User’s Table List ORACLE may print tables that hold some general information about the tables in your database Such Tables are: Tab, Cat, User_Tables (too detailed...) To see the list of all your tables you can print: SELECT * FROM Cat; SELECT tname FROM Tab; SELECT table_name from User_Tables;

6 Table Data Maintenance

7 The Employee Table > Describe Employee Name Null? Type SSN NUMBER FNAME VARCHAR2(20) LNAME VARCHAR2(20) GENDER CHAR(1) SALARY NOT NULL NUMBER(5)

8 Inserting a Row To insert a row into the Employee table: INSERT INTO Employee(SSN, Fname, Lname, Salary) VALUES(121, ‘Sara’, ‘Cohen’,10000); The remaining columns get default values (or NULL) Order is not important When will this fail?

9 Some More Details… The fields needn’t be specified if values are specified for all columns and in the order defined by the table Example: INSERT INTO Employee VALUES(121, ‘Sara’, ‘Cohen’, `F’, 10000);

10 Deleting Rows General format: DELETE FROM Table WHERE Cond; Deletes all rows satisfying Cond from Table For example, to remove the employee with SSN 121 from the Employee table: DELETE FROM Employee WHERE SSN = 121;

11 Deleting Rows (continues) To remove all male employees having a salary greater than shekels: DELETE FROM Employee WHERE Gender = ‘M’ AND Salary > 15000; The WHERE clause is basically the same as one in a query Case sensitive

12 Updating Rows (continues) We can update fields of rows in a table General format: UPDATE Table SET Field1=value1,,,FieldN=valueN WHERE Cond Now we can reduce salaries instead of firing employees: UPDATE Employee SET Salary = WHERE Gender = ‘M’ AND Salary > 15000;

13 The ORACLE Bulk Loader A tool that provides easy insertion of large amounts of rows into tables. The idea: the field values of the rows are kept in a file, the format of which is defined by us. For example, it can automatically load 3 employees from the file myEmployees.dat that contains the following lines: Sara|Cohen|121 Benny|Kimelfeld|134 Yaron|Kanza|156

14 The Control File The control file is the direct input of the loader A simple control file: LOAD DATA INFILE [APPEND] INTO TABLE FIELDS TERMINATED BY ' ‘ ( )

15 The Control File (continues) : The name of the data file : The name of the table into which the data will be loaded (appended if APPEND is specified, or else the table must be empty) : A string that separates two field values of a row The attributes are separated by commas and enclosed in parentheses

16 The Control File (continues) As an example, the following control file loads the employees from myEmployees.dat: LOAD DATA INFILE myEmployees.dat INTO TABLE Employees FIELDS TERMINATED BY '|' (Fname, Lname, SSN) The attributes that are unspecified will be set to NULL

17 The Data File The Bulk Loader considers every single line to represent one row in the table Even an empty line! (which will usually result in an error) Spaces are not ignored in the data file! thus the rows sara| cohen|121 and sara|cohen|121 define different functionalities The NULL value is implied by the NULL keyword or the empty string

18 The Data File (continues) The control and the data files can be combined into one.ctl file using the following format: LOAD DATA INFILE * INTO TABLE Employees FIELDS TERMINATED BY '|' (Fname, Lname, SSN) BEGINDATA Sara|Cohen|121 Benny|Kimelfeld|134 Yaron|Kanza|156

19 The Bulk Invocation To invoke the bulk loader, issue the following command directly from the Unix shell: sqlldr control= log= bad= All fields are optional File names that have no extension are automatically extended (by.dat,.log or.bad) Erroneous lines in the data file are ignored and written into badFile, and any other relevant information is written into logFile.

20 Bulk Loader Important Remarks Before using the Bulk Loader, make sure your personal ORACLE environment is properly set up The tables you fill using the Bulk Loader should be created prior to the loader invocation Before invoking the Bulk Loader you have to make sure that NO SQLPLUS SESSIONS ARE OPEN!