Instructor: Samia arshad

Slides:



Advertisements
Similar presentations
1 I Esempio di constraints. 2 DROP TABLE regions; CREATE TABLE regions ( region_id NUMBER CONSTRAINT region_id_nn NOT NULL, region_name VARCHAR2(25) );
Advertisements

CREATE TABLE famille( ( NomCol1 type [NOT NULL], … NomColn type [NOT NULL], PRIMARY KEY (NomColi, NomColj,…), FOREIGN KEY (NomColk, NomColv,…)REFERENCES.
Alter an existing Table Note: (a) Primary key: SID + Course_code.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
Using Relational Databases and SQL
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
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 DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
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.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Advanced Database Management System
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.
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.
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.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
UNIVERSITAS BINA DARMA 2013 DATA DEFINITION LANGUAGE (DDL)
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
Fundamentals of DBMS Notes-1.
Rob Gleasure robgleasure.com
Fundamental of Database Systems
Rob Gleasure robgleasure.com
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Including Constraints
SQL: Schema Definition and Constraints Chapter 6 week 6
Insert, Update and the rest…
Constraints and Triggers
MySQL Explain examples
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
STRUCTURED QUERY LANGUAGE
Structured Query Language (Data definition Language)
Lecturer: Mukhtar Mohamed Ali “Hakaale”
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
CS4222 Principles of Database System
SQL data definition using Oracle
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
CS122 Using Relational Databases and SQL
Oracle Data Definition Language (DDL)
Rob Gleasure robgleasure.com
Database Management System
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Data Definition Language
Data Definition Language
CS122 Using Relational Databases and SQL
Instructor: Mohamed Eltabakh
Oracle : SQL.
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Instructor: SAMIA ARSHAD
CS122 Using Relational Databases and SQL
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
Trainer: Bach Ngoc Toan– TEDU Website:
SQL (Structured Query Language)
Presentation transcript:

Instructor: Samia arshad Alter Table Instructor: Samia arshad

More SQL Data Definition Changing Tables Sometimes you want to change the structure of an existing table One way is to DROP it then rebuild it This is dangerous, so there is the ALTER TABLE command instead ALTER TABLE can Add a new column Remove an existing column Add a new constraint Remove an existing constraint More SQL Data Definition

More SQL Data Definition ALTERing Columns Examples: Suppose we have a table student having id and degree column ALTER TABLE Student ADD Degree VARCHAR(20) DROP COLUMN Degree To add or remove columns use ALTER TABLE <table> ADD <col> DROP COLUMN <name> More SQL Data Definition

More SQL Data Definition ALTERing Columns Examples Changing attribute type: ALTER TABLE Student Modify Degree CHAR(5) Renaming attribute: CHANGE Degree Degree1 varchar(25) To change existing attribute type and renaming a column ALTER TABLE <table> Modify <col> Alter TABLE <table> CHANGE <oldname> <newname> type(size) More SQL Data Definition

More SQL Data Definition Adding Constraints Examples Adding constraint: Unique Constraint ALTER TABLE STUDENT ADD CONSTRAINT ck UNIQUE (DEGREE) Not Null constraint alter table STUDENT modify Degree varchar(25) Not Null; To add or remove columns use ALTER TABLE <table> ADD CONSTRAINT <definition> ALTER TABLE <table name> modify <column name> type(size) not null; More SQL Data Definition

More SQL Data Definition Adding Constraints Primary Key ALTER TABLE STUDENT ADD CONSTRAINT pk Primary key (id) Foreign key ALTER TABLE STUDENT ADD CONSTRAINT fk Foreign key (column name) references primary table(column name) More SQL Data Definition

More SQL Data Definition Adding constraints Check ALTER TABLE STUDENT ADD CONSTRAINT chk check (id>10) More SQL Data Definition

More SQL Data Definition Dropping Constraint Dropping Constraint: ALTER TABLE STUDENT DROP foreign key constraintname; Dropping Not Null constraint ALTER TABLE student CHANGE column name column name int(25) null; ALTER TABLE <table> DROP CONSTRAINT <name> More SQL Data Definition

More SQL Data Definition Dropping Constraint To drop primary key, check, unique constraint, the following syntax will be used Alter table STUDENT drop index constraintname; More SQL Data Definition

More SQL Data Definition Drop table Examples Drop TABLE student Drop table Drop TABLE <table name> More SQL Data Definition