ROW in DBMS
DBMS ROWS
On this page we will discuss about ROWS in DBMS. The term row is often also called tuple and record in a database table . It is an important concept of DBMS.So, lets just discuss it in detail.
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’ENAME | JOB | SAL | HIREDATE | HIREDATE+2 |
---|---|---|---|---|
KING | PRESIDENT | 5000 | 17-NOV-81 | 19-NOV-81 |
BLAKE | MANAGER | 2850 | 01-MAY-81 | 03-MAY-81 |
CLARK | MANAGER | 2450 | 09-JUN-81 | 11-JUN-81 |
JONES | MANAGER | 2975 | 02-APR-81 | 04-APR-81 |
SCOTT | ANALYST | 3000 | 19-APR-87 | 21-APR-87 |
FORD | ANALYST | 3000 | 03-DEC-81 | 05-DEC-81 |
SMITH | CLERK | 800 | 17-DEC-80 | 19-DEC-80 |
SQL Query to retrieve particular rows
SELECT * FROM EMP WHERE DEPTNO=20;O/P
4 rows selected.
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
---|---|---|---|---|---|---|---|
7566 | JONES | MANAGER | 7839 | 02-APR-81 | 2975 | – | 20 |
7788 | SCOTT | ANALYST | 7566 | 19-APR-87 | 3000 | – | 20 |
7902 | FORD | ANALYST | 7566 | 03-DEC-81 | 3000 | – | 20 |
7369 | SMITH | CLERK | 7902 | 17-DEC-80 | 800 | 500 | 20 |
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.
ROWNUM | EMPNO | ENAME | JOB | SAL | DEPTNO |
---|---|---|---|---|---|
1 | 7839 | KING | PRESIDENT | 5000 | 10 |
2 | 7698 | BLAKE | MANAGER | 2850 | 30 |
3 | 7782 | CLARK | MANAGER | 2450 | 10 |
4 | 7566 | JONES | MANAGER | 2975 | 20 |
5 | 7788 | SCOTT | ANALYST | 3000 | 20 |
6 | 7902 | FORD | ANALYST | 3000 | 20 |
7 | 7369 | SMITH | CLERK | 800 | 20 |
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.
ROWNUM | EMPNO | ENAME | JOB | SAL | DEPTNO |
---|---|---|---|---|---|
1 | 7839 | KING | PRESIDENT | 5000 | 10 |
2 | 7698 | BLAKE | MANAGER | 2850 | 30 |
3 | 7782 | CLARK | MANAGER | 2450 | 10 |
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment