Beruflich Dokumente
Kultur Dokumente
DROP Command:
The SQL DROP Command is use to delete all records
and schema of the table.
Syntax:
DROP Table <table name>;
Example:
Drop table emp;
Give the syntax and example of CREATE and RENAME Commands. (Each
Command
The Syntax for the CREATE TABLE command is: Syntax with
CREATE TABLE <table_name> example: 2
2. (<column_name1>< datatype>(size), marks)
<column_name2>< datatype> (size),
.
.
<column_nameN>< datatype> (size));
For Example:
To create the employee table, the statement would be like,
CREATE TABLE employee
(emp_id number(5),
name char(20),
deptno number(2),
dob date,
salary number(10,2),
address varcharchar2(30) );
3.Modify column:-We can change the data type and/or size of a column
in a table by using modify clause in ALTER table. The size of the
column can be increased or decreased if the column contains only null
values or if the table has no rows.
Student_details
5.
1.
Explain Inner join and Outer join with example. (Inner join
:Explanation
INNER Join: 1 mark,
This is a simple JOIN in which the result is based on matched data as per Example 1
the condition specified in the query. mark, Outer
join :
Inner Join Syntax : Explanation
SELECT column_name_list 1 mark,
from table_name1 Example 1
INNER JOIN mark)
table_name2
on table_name1.column_name = table_name2.column_name;
2)Union all : The Union of 2 or more sets contains all elements, which are
present in both, including duplicates.
Eg select ename from emp1 union all select ename from emp2;
4)Minus: The minus of 2 sets includes elements from set1 minus elements
of set2.
Eg select ename from emp1 minus select ename from emp2;
2)add_months(d,n)
where d-date, n-number of months to be added to the date
Return date after adding the number of months specified with the function.
Example:
Select add_months(hiredate,2) from emp where empno
=7369;
3)next_day(d,char)
where d-date, char-day of week.
Return the date of the first weekday named ‘char’ that is later than date ‘d’.
Example:
Select next_day(‘01-FEB-2006’, ‘Wednesday’) “nex
t_day” from dual;
4)Last_day(d)
Where d-date
Return the last day of the month that contain date ‘d’. Used to determine
how many days left in a month.
Example:
Select last_day(sysdate) “last” from dual;
5)round(date,[fmt])
where ‘fmt’-format model: Month,Day.Year
Return date rounded to the unit specified by the format model ‘fmt’. If the
format model ’fmt’ is omitted, date is rounded to the nearest date.
Example:
Select round(sysdate, ‘day’) “round_day” from dual;
6)trunc(date,[fmt])
where ‘fmt’-format model: Month, Day, Year
Return date with the time portion of the day truncated to the unit specified
by the format model fmt. If the format model fmt is omitted, date is
truncated to the nearest day.
Example:
Select trunc(sysdate, ‘day’) “trunc_day” from dual;
Savepoint:
A SAVEPOINT is a point in a transaction when you can roll the
5. transaction back to a certain point without rolling back the entire
transaction.
The syntax for SAVEPOINT command is as follows:
SAVEPOINT SAVEPOINT_NAME;
e.g.
SAVEPOINT SV1;
Rollback:
The ROLLBACK command is used to undo transactions that have not
already been saved to the database.
The ROLLBACK command can only be used
to undo transactions since the last COMMIT or ROLLBACK command
was issued.
The syntax for rolling back to a SAVEPOINT is as follows:ROLLBACK
TO SAVEPOINT_NAME;
e.g.
ROLLBACK TO sv1;
What are sequences? Why it is used? Create sequence for STUDENT (Definition
table. -1 mark;
Use -1 mark;
Definition: creating valid
A sequence refers to a database object that is capable of generating unique sequence
and sequential integer values. example/
Use: pattern
1. 1.It saves a time by reducing application code. -2 marks)
2.It is used to generate unique sequential integers.
3.It is used to create an auto number fields.
4.Sequence can be use for many tables/relations
Create view EMPVIEW as select empname, empid, dob, salary, job from
3. employee where salary>20000;
OR
Example :
Create view emp_info as select Emp_no, Emp_name from Employee
where salary>12000;
Types of Index:
Simple index(Single column):
An index created on single column of a table is called a Simple Index.
Unique indexes
are used not only for performance, but also for data integrity. A unique
index does not allow any duplicate values to be inserted into the table.
Composite (concatenated):
Indexes that contain two or more columns from the same table which are
useful for enforcing uniqueness in a table column where there’s no single
column that can uniquely identify a row.
(OR)
Example
CREATE or REPLACE TRIGGER After_Update_Row_product
AFTER
insert On product
FOR EACH ROW
BEGIN
INSERT INTO product_check Values('After update, Row level',sysdate);
END;
Advantages of triggers:
1.Triggers provide an alternative way to check the integrity of data.
2.Can catch errors in business logic in the database layer.
3.SQL triggers provide an alternative way to run scheduled tasks.
4.Triggers are very useful to audit the changes of data in tables.
3.
Syntax:
LOCK TABLE
TABLE-NAME
3. IN {SHARED | EXCLUSIVE} MODE;
Types of Locks:
Shared Lock
Exclusive Lock.
Example:
Grant select,update on emp to user1;
5.
Revoke:
This command is used to withdraw the privileges that has been granted to a
user.
Syntax: Revoke
<object privileges>
on
<object name>
from
<username> ;
Example:
Revoke select, update on empfrom user1;