ROW in DBMS

ROW in DBMS

 

In this article, we will learn about ROW in DBMS.

  • Generally, the database table is  viewed  as a collection of rows and columns
  • The term row  is often also called tuple and record in a database table.

 

Learn about DROP in DBMS here on this page.

ROW in DBMS

ROW

Each row represents a complete record of the specific data item, each row stores different data with the same structure

Example

For example in an employee table, we need to store the details of 10 employees then the database table will consist of 10 rows every each row contains details of that particular employee i.e 1 row for storing the record of one employee

Consider a sample table ‘emp’

ENAMEJOBSALHIREDATEHIREDATE+2
KINGPRESIDENT500017-NOV-8119-NOV-81
BLAKEMANAGER285001-MAY-8103-MAY-81
CLARKMANAGER245009-JUN-8111-JUN-81
JONESMANAGER297502-APR-8104-APR-81
SCOTTANALYST300019-APR-8721-APR-87
FORDANALYST300003-DEC-8105-DEC-81
SMITHCLERK80017-DEC-8019-DEC-80

Table contents seven rows i.e it stores the details of all the 7 employees in 7 separate rows.

 

SQL Query to retrieve particular rows

SELECT * FROM EMP
WHERE DEPTNO=20;

O/P

4 rows selected.
EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7566JONESMANAGER783902-APR-81297520
7788SCOTTANALYST756619-APR-87300020
7902FORDANALYST756603-DEC-81300020
7369SMITHCLERK790217-DEC-8080050020

Only those rows corresponding to the details of Department number 20 are displayed.

 

ROW NUM in SQL

  • The rownum clause  in SQL is used to specify the number of rows present in a database table
  • Each row will be added a number starting from 1 to n so that the user can easily identify the number of rows present in the table

Example

select rownum,empno,ename,job,sal,deptno 
FROM EMP;

O/P

7 rows selected.
ROWNUMEMPNOENAMEJOBSALDEPTNO
17839KINGPRESIDENT500010
27698BLAKEMANAGER285030
37782CLARKMANAGER245010
47566JONESMANAGER297520
57788SCOTTANALYST300020
67902FORDANALYST300020
77369SMITHCLERK80020

 

Displaying top N rows

Suppose if you want to display the top three rows present in emp table then you can use this rownum along with the relational operator

Example

select rownum,empno,ename,job,sal,deptno 
FROM EMP
where rownum<=3;

O/P

3 rows selected.
ROWNUMEMPNOENAMEJOBSALDEPTNO
17839KINGPRESIDENT500010
27698BLAKEMANAGER285030
37782CLARKMANAGER245010

Only the first 3 rows in a table or displayed