Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Wednesday, 29 January 2014

ORACLE - SQL Query - 3

Query to display first n records of the table

Structure and data of the table i used

 query to display first n records of the table. where &n is a substitution variable in oracle, whose values can be assigned at runtime, very much similar to scanf function in C language

rownum column i used here is a pseudo-column supplied from oracle with every table that you create. Be sure with the behaviour of rownum. check the below queries to understand the behaviour




Friday, 13 December 2013

ORACLE - SQL Query - 2

Query to display 1st highest,2nd highest salary earners.

This is the table i am using here.

Query to display 1st highest earners

Query to display 2nd highest earners

Monday, 11 March 2013

difference between truncate, delete and drop command in sql?

this is one of the most frequently asked question in interviews

The DELETE command is used to remove rows from a table and DELETE operation is temporary you need to either COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. By using DELETE we can delete only selected rows as per our requirement.

TRUNCATE removes all rows from a table. The operation cannot be rolled back. TRUNCATE is faster and doesn't use as much undo space as a DELETE.
The DROP command removes a table and its related indexes and privileges from the database.The operation cannot be rolled back.
DELETE and TRUNCATE both are DML commands where as DROP is a DDL command.

Sunday, 2 September 2012

what is First Normal Form ??

1. eliminate repeating groups in individual tables.
2. create a separate table for each set of related data.
3. identify each set of related data with a primary key.

what is normalization and for what it is meant for ??

Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating two factors: redundancy and inconsistent dependency. 

Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one place must be changed, the data must be changed in exactly the same way in all locations. A customer address change is much easier to implement if that data is stored only in the Customers table and nowhere else in the database. 

What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table for the address of a particular customer, it may not make sense to look there for the salary of the employee who calls on that customer. The employee's salary is related to, or dependent on, the employee and thus should be moved to the Employees table. Inconsistent dependencies can make data difficult to access; the path to find the data may be missing or broken. 

There are a few rules for database normalization. Each rule is called a "normal form." If the first rule is observed, the database is said to be in "first normal form." If the first three rules are observed, the database is considered to be in "third normal form." Although other levels of normalization are possible, third normal form is considered the highest level necessary for most applications.