Difference between varchar and varchar2?
Answered by: muralidhar_batta
View all answers by muralidhar_batta
Member Since Feb-2006 | Answered On : Feb 26th, 2006
varchar means fixed length character data(size) ie., min size-1 and max-2000
where as varchar2 means variable length character data ie., min-1 to max-4000
Varchar & Varchar2 both having the same size, & working as same.
Bt the main diff is varchar is an ANSI Datatype & Varchar2 is the Oracle datatype.
Varchar - If we declare datatype as varchar then it will occupy space for null values. It can store upto 2000 bytes of character.
Varchar2 - If we declare datatype as varchar2, it will not occupy any space. It can store 4000 bytes of character.
Thanx,
How do you print the last n rows or the first n rows of a table ?
Answered by: nirmal1in
View all questions by nirmal1in View all answers by nirmal1in
Member Since Jan-2010 | Answered On : Jan 16th, 2010
This can be accomplished in following way:
Example: table - emp
For First n rows:
SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a < 5 --- say n is 5 display first 5 records
For last n rows:
SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename) a
FROM emp) x
WHERE x.a < 5
This query can be used for finding nth row also say n = 5
SELECT * FROM
(SELECT empno,ename,job,row_number() over (order by ename desc) a
FROM emp) x
WHERE x.a = 5
Code
SELECT rownum,a.*FROM(SELECT rownum,b.*FROM emp b ORDER BY rownum DESC) a WHERE rownum <&n;
For First N Rows:
What is the main use of foreign key?
Answered by: MANAS KUMAR ROUT ( USA ) (TCS) (Eli LILLY ) - PFIZ
Answered On : Jul 5th, 2007Hey Ramesh,
I understand your interviewer's enthusiasm to know about the Foreign Key. See foreign key definitions says its states the relationship of one attribute(Column) of one table to the corresponding column on the other table.
So one os a parent and other is child. PARENT is that table which holds the primary key and CHILD is table which holds the referential key. Hence every entry in the PRIMARY table is unique where as same entry might be repeating in the child table. BUT that same has to be present in the PARENT table (Primary KEY).
Now Going by definition Foreign key can be of two types :
========================================
1. ON DELETE SET NULL
2. ON DELETE SET CASCADE
DETAILS:
=======
On delete set null :
=======
When a foreign key is created by on delete set null definition then when you delete one row from the primary column (of parent table ) , then the corresponding entry in the foreign key table (Child table ) have the value "NULL" for that particular column.
ON Delete Set Cascade:
================
When the foreign key is created by this definition then when you delete the primary column (any one row -unique data) , then the Child table forcefully deletes all the rows in the child table having same value for that particular column.
I hope u got the crux of the Foreign key
Thanks
Manas Kumar Rout
SAS Consultant
Oracle Certified Associate
Unix Consultant
foreign key is primary key of other table. for example: 'STUDENT' is one table which stores information about students and 'SID' is primary key in that table and 'MARKS' is another table which stor...
The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted. For example, say we have two tab...
What is dual table which is used as a table in SQL...
Answered by: svsraju81
Member Since Jul-2008 | Answered On : Jul 24th, 2008
Dual table is a temporary table, it contains a single row and single column. If we return a data from dual table it gives a single row.
Dual table is called a dummy table because it is not meant for storing any useful data.
Dual table is owned by SYS. Data dictionary come under SYS, dual is part of data dictionary. Dual table consist only one row and only one column containing value x
I have a very unusual question, how can one check which is the recent row added to a table?
Answered by: biswaranjanbehera
View all answers by biswaranjanbehera
Member Since Jul-2008 | Answered On : Aug 6th, 2008
We can select the recent row enrtered by using the query below.
suppose the table name is employee;
then.
select * from employee where rowid=(select max(rowid) from employee).
This works fine because rowid is assigned for each and every record and in accending order. So the recent record's rowid is the man (rowid). Please send feedback with any concern.
"Although a rowid uniquely identifies a row in a table, it might change its value if the underlying table is an index organized table or a partitioned table." Also rowid stores information a...
SCOPE_IDENTITY() would be a better option to get the most recently added row as the primary key for a table may not necessarily be an auto-incrementing variable. Therefore max(rowid) would not be the optimal solution in that case.
Editorial / Best Answer
Answered by: Sushant
Answered On : Oct 25th, 2006The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db.
now SQL SERVER 2008 onwards we can have 1 cluster index and 999 non cluster index on one table.
clustered index - the index order matches the order of physically stored data.cluster index can be used on table that doent get changes frequentlyusing DML statement on cluster index column have...