Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Record

Records in DBMS

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

RECORD

Each record represents complete information of the specific  data item, each record 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 records every each record contains details of that particular employee i.e 1 record for storing the information 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
Record

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

SQL Query to retrieve particular records

SELECT * FROM EMP
WHERE DEPTNO=20;
Output :
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 rcords present in a database table
  • Each record will be added a number starting from 1 to n so that the user can easily identify the number of records present in the table

Example

select rownum,empno,ename,job,sal,deptno 
FROM EMP;
Output :
7 rows selected.
ROWNUMEMPNOENAMEJOBSALDEPTNO
17839KINGPRESIDENT500010
27698BLAKEMANAGER285030
37782CLARKMANAGER245010
47566JONESMANAGER297520
57788SCOTTANALYST300020
67902FORDANALYST300020
77369SMITHCLERK80020

 

Displaying top N records

Suppose if you want to display the top three records 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;
Output :
3 rows selected.
ROWNUMEMPNOENAMEJOBSALDEPTNO
17839KINGPRESIDENT500010
27698BLAKEMANAGER285030
37782CLARKMANAGER245010

Only the first 3 records in a table or displayed