This Study Resource Was: Aim: To Know How The Constraints Are Used To Make Table Is Consistent
This Study Resource Was: Aim: To Know How The Constraints Are Used To Make Table Is Consistent
This Study Resource Was: Aim: To Know How The Constraints Are Used To Make Table Is Consistent
Table
Name: Employee
Attribute Data Type Constraint
First Name Varchar (15) Not Null
Mid Name Char(2)
Last Name Varchar (15) Not Null
SSN Number Char (9) Primary Key
Birthday Date
Address Varchar (50)
Sex Char(1) Sex In (M,F,m,f)
Salary Number (7) Default 800
Supervisor SSN Char (9) Foreign Key Employee (SSN) on delete set null
Dept no Number(5) Foreign key to dept no of department table
sql:
CREATE TABLE EMPLOYE1(FIRST_NAME VARCHAR(15) CONSTRAINT CFNAME_NN NOT
m
er as
NULL,
MID_NAME CHAR(2),
co
eH w
LAST_NAME VARCHAR(15) CONSTRAINT CLNAME_NN NOT NULL,
SSNNO CHAR(9) CONSTRAINT CSSN_PK PRIMARY KEY, BIRTHDAY
o.
DATE, rs e
ADDRESS VARCHAR(50),
ou urc
SEX CHAR(1) CONSTRAINT CSEX_SI CHECK (SEX IN('F','M','f','m')),
SALARY NUMBER(7),
SUPERVISORSSN CHAR(9),
o
DEPT_NO NUMBER(5));
v i y re
Manager SSN Char (9) Foreign key-Employee (SSN) on delete set null
ar stu
sql:
sh is
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
ALTER TABLE EMPLOYE1 ADD CONSTRAINT CODEP_FK FOREIGN KEY(DEPT_NO) REFERENCES
DEPARTMENT(DEPT_NO);
Table Name: Project
Attribute Data type Constraint
Project Name Varchar2(15) Not Null
Project number Number(5) Primary key
Project Location Varchar2(50)
Foreign Key –Department (dep no) on delete set
Dept no Number(5) cascade
sql:
CREATE TABLE PROJECT1(PROJECT_NAME VARCHAR(15) CONSTRAINT CPNAME_NN NOT NULL,
PROJECT_NO NUMBER(5) CONSTRAINT CPNO_PK PRIMARY KEY,
PRO_LOC VARCHAR2(50),
DEPT_NO NUMBER(5),
CONSTRAINT DEPT1_FK FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO) ON
m
DELETE CASCADE);
er as
Execute the following Query on the Db to display and discuss the integrity
co
constraints violated by any of the following operations
eH w
1. Insert ('Robert', 'F', 'Scott', '235', '21-JUN-1990', 'Bangalore', M, 58000, '100', 1 ) into
o.
rs e
ou urc
sql: EMPLOYEE.
INSERT INTO EMPLOYE1 VALUES('Robert',
o
'F',
aC s
'Scott',
v i y re
'235',
'21-JUN-1990',
'Bangalore',
ed d
'M',
ar stu
58000,
'100',
1 );
sh is
Output:
Th
The table department contains dept_no as primary key and there are no
values inserted into department. dept_no column is foreign key in table
department ,so it shows an error that its parent table doesn’t have this
value.
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
2. Insert ( 'ProjectF', null, 'Chennai', 3 ) into Project.
sql:
INSERT INTO PROJECT1 VALUES( 'ProjectF', NULL, 'Chennai', 3);
Output:
Output:
m
er as
co
eH w
o.
The table department contains dept_no as primary key.dept_no column is
rs e
foreign key in table department ,so it shows an error that its parent table
ou urc
doesn’t have this value.
o
aC s
1. Add Foreign Keys using Alter Table [if not done earlier].
sql:
ed d
2. Drop Foreign key defined on SuperSSN and add it using Alter table command.
sql:
sh is
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
STREET VARCHAR(10),
CITY VARCHAR(10),
STATE VARCHAR(10),
CONTINENT VARCHAR(10));
5. Make salary of employee to accept real values.
sql:
ALTER TABLE EMPLOYE1 MODIFY(SALARY NUMBER(7,2));
Output
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
This study source was downloaded by 100000815968135 from CourseHero.com on 09-24-2021 06:55:48 GMT -05:00
https://www.coursehero.com/file/34579392/constraintsdocx/
Powered by TCPDF (www.tcpdf.org)