Can we give unique and not null constraint to an attribute? How it is different from primary key?
Yes We can. If we use the combination "unique+not null" the referential integrity is not maintained and that is not the case with primary key.
There is only one primary key per table but we can use unique and not null constraints more than one column in a table. Primary key having both functionality as it can not be null but unique.
List the premium customers who is not using the service within the last one week.
List the premium customers who is not using the service within the last one week.If you have these tables: 1-'premuim_user'columns: customer_id, post_paid.2-'calls'columns: called_number, customer_id, call_date, call_time_started, call_time_ended, transaction_no.
No, you cant insert column between existing columns in oracle database but, you can add or insert column in a table at end of last column.
Oracle doesnt allow inserting column in between two. But there are work around to do this. Simple and best one is to add the new column at the end of table. Then rename that table, renaming table will...
If in a table we dont use primary key or any other unique key then how to avoid duplication of data?
Its impossible to avoid duplication without constraint the PK on Column
We must constraint the column with primary key when designing the database to avoid the duplications.
By using merge statement we can do it simply.
Use merge stat
How to fetch alternate rows from the table?
Code
SELECT * FROM EMP WHERE (ROWID,1) IN (SELECT ROWID,MOD(ROWNUM,2) FROM EMP); OR SELECT * FROM (SELECT EMP.*,ROWNUM K FROM EMP) WHERE MOD(k,2)=0;
Code
SELECT * FROM table_name WHERE mod(primary_key_column,2)=0 --to find even rows in a table SELECT * FROM employees WHERE mod(employee_id,2)=0 --to find even rows in a table SELECT * FROM employees WHERE mod(employee_id,2)=1 --to find odd rows in a table
Retrieve rows without using select clause
How can we retrieve some rows from the database without using select clause?
Select clause is must for retrieving data from the database. You cant retrieve data without select clause.
Impossible! Rows will not be rerieved without select keyword.
What is set transaction command in SQL? What is its use. Explain with examples
The null column in the output will come in the last i.E at the end. Why?E.G comm 1200 1000 1300 1450 ---- (null) ---- (null)
SEE THIS ALSO,
Code
SELECT EMPNO,ENAME,JOB,COMM FROM EMP ORDER BY COMM NULLS LAST;
Nulls are unassigned and unavailable values.i.e. null means "no value".
So in order to obtain values the values get preference over the no values(null).
g means Grid Computing..
grid computing
How to find out department wise second maximum salary.
"sql SELECT DISTINCT d1.depno, e1.salary,e1.empid,d1.location FROM EMPLOYEE1 e1, dept d1 WHERE 2 = (SELECT count(DISTINCT e2.salary) FROM EMPLOYEE1 e2...
Code
SELECT min(salary) FROM dept WHERE salary IN ( SELECT DISTINCT top 2 salary FROM dept ORDER BY salary DESC)
What is the difference between no data found and %notfound ?
How do you know which index a table is using?
How to avoid duplication in database if we are adding data from .Dat file ?
What is the use of lEFT outer & right outer join, using equi join with union we can do the outer join then why we need to go for outer join
Left outer Join fetch all the records from Left side Table(Only Condition satisfied records from right side table) where as Right Outer Join fetch all the records from Right side Table(Only Condition satisfied records from Left side table).
Using Equi Join with Union we can do the outer join then why we need to go for Outer Join -- increase the performance
How to insert a record in two tables with single insert statement ?
Answer:
Code
INSERT ALL INTO first_table VALUES(value1,value2) INTO second_table VALUES(value1,value2) SELECT * FROM dual;
Using merge concept, we can insert a record at a time into two tables.
How to display middle record in a given table?
The below code selects the exact middle row from the table
Code
SELECT * FROM TABLE WHERE rownum=trunc(SELECT count(*)/2 FROM TABLE)
The below code returns the rows from 50-74
Code
TO SELECT the middle rows: SELECT * FROM TABLE offset 50 rows fetch next 25 rows only
What is the difference between SQL & PL/SQL?
1.Sql is a declarative language.It tells only what to do. PL/Sql is a procedural language.It tells what to do and how to do. 2.Sql executes DDL and DML statements . Pl/Sql executes triggers,func...
sql is structured query language and plsql is procedural sql. in sql we write a query to fetch the data from data base. in pl sql we write the set of sql command and execute it in one times. the benef...
Alter trigger trigger_name disable/enable all triggers.
Alter trigger Disable;