The document discusses data types, constraints, and check constraints in Oracle databases. It provides examples of creating tables with various column constraints like NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, and CHECK constraints. It also gives examples of creating tables for a customer, employee, and department database with the relevant constraints.
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0 ratings0% found this document useful (0 votes)
55 views7 pages
Data Types in Oracle
The document discusses data types, constraints, and check constraints in Oracle databases. It provides examples of creating tables with various column constraints like NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, and CHECK constraints. It also gives examples of creating tables for a customer, employee, and department database with the relevant constraints.
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 7
Data Types in Oracle
• The datatype of a value associates a fixed set
of properties with the value. • Char • Varchar2 • Nvarchar2 • Number • Float • Long datatypes (clob,nclob,blob) FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License COnstraints • Constraint keyword is used to define an integrity constraint • A CONSTRAINT can be one of the following: • a column-level constraintColumn-level constraints refer to a single column in the table and do not specify a column name (except check constraints). They refer to the column that they follow. • a table-level constraintTable-level constraints refer to one or more columns in the table. Table-level constraints specify the names of the columns to which they apply. – Table-level CHECK constraints can refer to 0 or more columns in the table.
FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
•A NOT NULL constraint prohibits a database value from being null. •A unique constraint prohibits multiple rows from having the same value in the same column or combination of columns but allows some values to be null. •A primary key constraint combines a NOT NULL constraint and a unique constraint in a single declaration. It prohibits multiple rows from having the same value in the same column or combination of columns and prohibits values from being null. •A foreign key constraint requires values in one table to match values in another table. •A check constraint requires a value in the database to comply with a specified condition.
FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
Check Constraint • A check constraint can be used to specify a wide range of rules for the contents of a table. A search condition (which is a boolean expression) is specified for a check constraint. This search condition must be satisfied for all rows in the table. The search condition is applied to each row that is modified on an INSERT or UPDATE at the time of the row modification. The entire statement is aborted if any check constraint is violated. • Requirements for search condition • If a check constraint is specified as part of a column-definition, a column reference can only be made to the same column. Check constraints specified as part of a table definition can have column references identifying columns previously defined in the CREATE TABLE statement. • Constraint constraint_name check (col_condition) • Example: create table orders (ordered number(5), order_date date, status varchar2 (10) constraint check_status CHECK (status IN (‘Cancel’,’pending’, ‘confirm’) FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License To do • Create table as below specification: tbl_Customer(cust_no number (5) NOT NULL, First_name varchar2(30) constraint unique_fname UNIQUE, last_name varchar2(30), address varchar2(50), city varchar2(30), state varchar2(30) DEFAULT ‘GUJARAT’, pincode varchar2(12), birth_date date,nationality varchar2(20) CONSTRAINT check_nation CHECK(nationality IN (‘Indian’,’American’,’nepali’)) ); FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License • Create table tbl_employee (empno number(4), ename varchar2(20),address varchar2(30), job varchar2(10), mgr number(4), hiredate date, sal number(7,2), comm number (7,2) deptno number(2)); • Create table tbl_dept( deptno number(2), deptname varchar2(10)
FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
Solve the following Queries • 1) display distinct jobs. • 2)display data of employee with empno, ename as name, hiredate as Join Date, sal as salary, job for those who are manager. • 3)Write a query to find the years of experience
FatMax 2007. Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License