Dbms Lab File
Dbms Lab File
Write SQL queries to create customer1, order1and display the structures of the
tables.
Desc customer1.
desc order1;
Program-2
Write SQL queries to add new column pincode,primary key (C_id) in customer1
and primary key (order_no) and foreign key C_id reference to customer1 using
alter command.
Primary key: A primary key is used to ensure that data in the specific column is
unique. A column cannot have NULL values.It is either an existing table column or
a column that is specifically generated by the database according to a defined
sequence.
Write SQL queries to insert and display the records in customer1 and oder1 using
insert command.
Ascending order
Descending Order
The SQL Join clause is used to combine data from two or more tables in a
database. When the related data is stored across multiple tables, joins help you to
retrieve records combining the fields from these tables using their foreign keys.
Natural Join
Outer Join
An Outer Join retrieves all the records in two tables even if there is no counterpart
row of one table in another table, unlike Inner Join. Outer join is further divided
into three subtypes - Left Join, Right Join and Full Join.
Retrieves all the records from the first table, Matching records from the second
table and NULL values in the unmatched rows.
Retrieves all the records from the second table, Matching records from the first
table and NULL values in the unmatched rows.
Retrieves records from both the tables and fills the unmatched values with NULL.
An INNER JOIN is the default join which retrieves the intersection of two tables.
It compares each row of the first table with each row of the second table. If the
pairs of these rows satisfy the join-predicate, they are joined together.
A view in SQL is a virtual table that is stored in the database with an associated name.
It is actually a composition of a table in the form of a predefined SQL query. A view
can contain rows from an existing table (all or selected). A view can be created from
one or many tables. Unless indexed, a view does not exist in a database.
Create view c1 as
desc c1;
Program-7
The outer query can contain the SELECT, INSERT, UPDATE, and DELETE
statements. We can use the subquery as a column expression, as a condition in
SQL clauses, and with operators like =, >, <, >=, <=, IN, BETWEEN, etc.
Write PL queries to Check whether the given number is even or odd number.
PL: PL/SQL is a block structured language that enables developers to combine the
power of SQL with procedural statements. All the statements of a block are passed
to oracle engine all at once which increases processing speed and decreases the
traffic.
declare
v1 number ;
begin
v1 :=:v1;
if mod(v1,2)=0 then
dbms_output.put_line('given number is even : ' || v1);
else
dbms_output.put_line('given number is odd : ' || v1);
end if;
end;
output:
Program-9
declare
x number;
begin
dbms_output.put_line(x);
end loop;
end;
Output
Program-10
declare
a number(4);
b number(4);
c number(4);
begin
a:=:a;
b:=:b;
c:=:c;
dbms_output.put_line(' a is greatest');
dbms_output.put_line('b is greatest');
else
end;
Output