Difference between revisions of "PostgreSQL-Database/C2/Alias-Names/English"
(Created page with "Title of the Script: Alias Names Author: EduPyramids Keywords: PostgreSQL, pgAdmin 4, alias, AS keyword, space, underscore, double quotes, video tutorial, EduPyramids. {|...") |
|||
| Line 16: | Line 16: | ||
|- | |- | ||
| − | || '''Slide 2''' | + | || '''Slide 2''' |
| + | |||
'''Learning Objectives''' | '''Learning Objectives''' | ||
|| In this tutorial, we will learn to, | || In this tutorial, we will learn to, | ||
| Line 28: | Line 29: | ||
|- | |- | ||
|| '''Slide 3''' | || '''Slide 3''' | ||
| + | |||
'''System Requirements''' | '''System Requirements''' | ||
| Line 42: | Line 44: | ||
|- | |- | ||
|| '''Slide 4''' | || '''Slide 4''' | ||
| + | |||
'''Pre-requisites''' | '''Pre-requisites''' | ||
|| To follow this tutorial, | || To follow this tutorial, | ||
| Line 49: | Line 52: | ||
|- | |- | ||
|| '''Slide 5''' | || '''Slide 5''' | ||
| + | |||
'''Code Files''' | '''Code Files''' | ||
The following code file is required to practice this tutorial: | The following code file is required to practice this tutorial: | ||
| Line 72: | Line 76: | ||
|- | |- | ||
|| Display the students table | || Display the students table | ||
| − | Type: | + | |
| + | Type: | ||
| + | |||
| + | '''SELECT * FROM students;''' | ||
| + | |||
|| Let us display the student table. | || Let us display the student table. | ||
Type the following query. | Type the following query. | ||
| Line 88: | Line 96: | ||
|- | |- | ||
|| '''Type:''' | || '''Type:''' | ||
| + | |||
'''SELECT studentname fullname FROM students;''' | '''SELECT studentname fullname FROM students;''' | ||
| + | |||
|| Let us create an alias using a '''space'''. | || Let us create an alias using a '''space'''. | ||
Type the following query. | Type the following query. | ||
| Line 94: | Line 104: | ||
|- | |- | ||
|| Highlight '''studentname fullname''' | || Highlight '''studentname fullname''' | ||
| + | |||
|| Here, '''studentname''' is the original column name. | || Here, '''studentname''' is the original column name. | ||
| + | |||
'''fullname''' is the alias given using a '''space'''. | '''fullname''' is the alias given using a '''space'''. | ||
| Line 120: | Line 132: | ||
|- | |- | ||
| − | || Type: '''SELECT studentid AS student_id FROM students;''' | + | || Type: |
| + | |||
| + | '''SELECT studentid AS student_id FROM students;''' | ||
|| Now let us use an '''underscore''' in the '''alias''' name. | || Now let us use an '''underscore''' in the '''alias''' name. | ||
Type the following query. | Type the following query. | ||
| Line 126: | Line 140: | ||
|- | |- | ||
|| Highlight '''student_id''' | || Highlight '''student_id''' | ||
| + | |||
|| Here, '''student_id''' is the '''alias''' name. | || Here, '''student_id''' is the '''alias''' name. | ||
The '''underscore''' is used to separate words for better readability. | The '''underscore''' is used to separate words for better readability. | ||
| Line 135: | Line 150: | ||
|- | |- | ||
| − | || '''Highlight: | + | || '''Highlight: SELECT studentid AS student_id FROM students;''' |
'''Type:''' | '''Type:''' | ||
| + | |||
'''SELECT studentid student_id FROM students;''' | '''SELECT studentid student_id FROM students;''' | ||
|| Here the '''AS''' keyword is optional, it means the query runs with or without '''AS'''. | || Here the '''AS''' keyword is optional, it means the query runs with or without '''AS'''. | ||
| Line 157: | Line 173: | ||
|- | |- | ||
| − | || Type: | + | || Type: |
| + | |||
| + | '''SELECT * FROM students;''' | ||
|| '''Alias''' names are temporary and do not modify the actual table structure. | || '''Alias''' names are temporary and do not modify the actual table structure. | ||
To check, let us type this query and execute it. | To check, let us type this query and execute it. | ||
Revision as of 15:35, 27 April 2026
Title of the Script: Alias Names
Author: EduPyramids
Keywords: PostgreSQL, pgAdmin 4, alias, AS keyword, space, underscore, double quotes, video tutorial, EduPyramids.
| Visual Cue | Narration |
|---|---|
| Title Slide 1 | Welcome to this Spoken Tutorial on Alias Names in PostgreSQL. |
| Slide 2
Learning Objectives |
In this tutorial, we will learn to,
|
| Slide 3
System Requirements To record this tutorial, I am using • Ubuntu 24.04 LTS, • PostgreSQL version 18.1, and • pgAdmin 4 version 9.11. |
To record this tutorial, I am using the following setup. |
| Slide 4
Pre-requisites |
To follow this tutorial,
|
| Slide 5
Code Files The following code file is required to practice this tutorial: • an-commands.txt This file is provided in the Code Files link on this tutorial page. |
The following code file is required to practice this tutorial.
This file is provided in the Code Files link of this tutorial page. Please download and extract the file. |
| Let us get started. | |
| Point to the interface. | I have opened the pgAdmin 4 interface and connected to the localhost server. |
| Display the students table
Type: SELECT * FROM students; |
Let us display the student table.
Type the following query. Click on the Execute query icon to run the query. Notice the student table with all the records. |
| Slide 5
What is an Alias? |
Let us see what an alias is?
An alias is a temporary name given to a column or a table. It improves the readability of the output. Alias names exist only for the duration of the query. |
| Type:
SELECT studentname fullname FROM students; |
Let us create an alias using a space.
Type the following query. |
| Highlight studentname fullname | Here, studentname is the original column name.
fullname is the alias given using a space. |
| Click on the execute query button. | Click on the Execute query button to execute the query.
The output displays the studentname column with the new heading fullname. |
| Type:
SELECT city AS studentcity FROM students; |
Now let us create an alias using the as keyword.
Type the following query. |
| Highlight city AS studentcity | Here, AS keyword explicitly assigns the alias name studentcity to the city column. |
| Click the Execute query icon
Point to the output.. |
Let us execute the query.
Observe the output. The original column name city is now replaced with studentcity. |
| Type:
SELECT studentid AS student_id FROM students; |
Now let us use an underscore in the alias name.
Type the following query. |
| Highlight student_id | Here, student_id is the alias name.
The underscore is used to separate words for better readability. |
| Click the Execute query icon. | Let us execute the query.
The column heading is now changed to student_id. |
| Highlight: SELECT studentid AS student_id FROM students;
Type: SELECT studentid student_id FROM students; |
Here the AS keyword is optional, it means the query runs with or without AS.
Let us type this query and execute it. Both the queries give the same result. |
| Type: SELECT cgpa AS "Student cgpa" FROM students; | Now let us create an alias using double quotes. Type the following query. |
| Highlight "student cgpa" | Here double quotes allow us to include spaces in the alias name.
Double quotes are required when the alias contains spaces. |
| Click the Execute query icon. | Let us execute the query.
The column heading cpga is now changed to student cgpa. |
| Type:
SELECT * FROM students; |
Alias names are temporary and do not modify the actual table structure.
To check, let us type this query and execute it. Observe that the actual table is not modified. |
| Slide 7
Summary In this tutorial we have learnt to, • Create alias names using: • space, • AS keyword, • underscore and • double quotes. |
With this we come to the end of this tutorial.
Let us summarise. |
| Slide 8
Assignment As an assignment, Create alias names for gender and date of birth columns using different methods of aliasing. SELECT * FROM students; |
As an assignment, please do the following. |
| Slide 9
Thank You This Spoken Tutorial is brought to you by EduPyramids Educational Private Limited, SINE IIT Bombay. |
Thank you. |