Tuple

Tuples in DBMS

On this page, we will learn about Tuple in DBMS.

  • Generally, the database table is  viewed  as a collection of tuples.
  • The term tuple  is often also called row and record in a database table.
Outer Join in SQL

TUPLE

Each tuple represents a complete record of the specific data item, each tuple 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 tuples  every each tuple contains details of that particular employee i.e 1 tuple 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 tuples

SQL Query to retrieve particular tuples

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 tuples corresponding to the details of Department number 20 are displayed.

Tuple img

ROW NUM in SQL

  • The rownum clause  in SQL is used to specify the number of tuples present in a database table
  • Each tuple will be added a number starting from 1 to n so that the user can easily identify the number of tuple 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 tuples

Suppose if you want to display the top three tuples 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 tuples in a table or displayed

Learn more about Record here on this page.

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

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription