Documente Academic
Documente Profesional
Documente Cultură
TYPES
Primary key
Foreign key
Unique
Not null
Check
NOT NULL
NOT NULL constraint makes sure that a column does not hold NULL value.
EX:
UNIQUE
CHECK
This constraint is used for specifying range of values for a particular column of a table.
EX:
PRIMARY KEY
FOREIGN KEY
Foreign keys are the columns of a table that points to the primary key of another table
They act as a cross-reference between tables.
EX:
insert into infosys
values('OM211','Daniel','danny@infosys.com','Programmer',5000,'21-May-2015');
insert into infosys
values('OM212','samuel','samuel@infosys.com','Programmer',8000,'27-Feb-2015');
insert into infosys
values('OM213','Arun','arun@infosys.com','Programmer',10000,'29-Mar-2015');
insert into infosys
values('OM214','Karthikeyan','karthi@infosys.com','clerk',8000,'11-JUN-2015');
insert into infosys values('OM215','Andrew','andrew@infosys.com','clerk',5000,'13-
sep-2015');
insert into infosys
values('OM216','Stewart','stewart@infosys.com','Programmer',15000,'19-JAN-
2015');
create table Infosys_employee_Details
(
emp_id varchar(2),
CITY char(20),
Country char(10),
EMAIL_ID varchar2(30),
Phone_number number(10),
Gender char(1),
constraint Infy_emp_id_fk FOREIGN KEY (emp_id) References (wrong don’t
follow )infosys(Employee_id) ON DELETE CASCADE,
constraint Infy_Email_FK FOREIGN KEY (Email_ID) References
infosys(Employee_email_id) ON DELETE SET NULL,
constraint Infy_emp_Gen CHECK (Gender IN ('F','M'))
);
A foreign key with cascade delete means that if a record in the parent table is deleted,
then the corresponding records in the child table will automatically be deleted. This is
called a cascade delete in SQL Server
A foreign key with cascade delete can be created using either a CREATE TABLE
statement or an ALTER TABLE statement
( Infosys_employee_details table)
A foreign key with "set null on delete" means that if a record in the parent table is
deleted, then the corresponding records in the child table will have the foreign key
fields set to null.
The records in the child table will not be deleted.
A foreign key with a "set null on delete" can be defined in either a CREATE TABLE
statement or an ALTER TABLE statement.
2Write a PL/SQL block to declare a variable called sal to store the salary of an
employee. In the executable part of the program, do the following:
c. If the salary is less than 3,000, give the employee a raise of 500 and
display the message “<Employee Name>’s salary updated” in the window.
d. If the salary is more than 3,000, print the employee’s salary in the format,
“<Employee Name> earns”
Note: “Undefine” the variable that stores the employee’s name at the end of the
script.