Difference between revisions of "PostgreSQL-Database/C2/Alias-Names/English"
| (4 intermediate revisions by 2 users not shown) | |||
| Line 60: | Line 60: | ||
This file is provided in the Code Files link on this tutorial page. | This file is provided in the Code Files link on this tutorial page. | ||
| + | |||
| + | Please download and extract the file. | ||
|| The following code file is required to practice this tutorial. | || The following code file is required to practice this tutorial. | ||
| Line 91: | Line 93: | ||
'''What is an Alias?''' | '''What is an Alias?''' | ||
|| Let us see what an alias is? | || Let us see what an alias is? | ||
| + | |||
An alias is a temporary name given to a column or a table. | An alias is a temporary name given to a column or a table. | ||
It improves the readability of the output. | It improves the readability of the output. | ||
| Line 155: | Line 158: | ||
'''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''' keyword. |
| + | |||
Let us type this query and execute it. | Let us type this query and execute it. | ||
| + | |||
Both the queries give the same result. | Both the queries give the same result. | ||
| Line 183: | Line 188: | ||
|- | |- | ||
|| '''Slide 7''' | || '''Slide 7''' | ||
| + | |||
'''Summary''' | '''Summary''' | ||
| + | |||
In this tutorial we have learnt to, | In this tutorial we have learnt to, | ||
| Line 202: | Line 209: | ||
|- | |- | ||
|| '''Slide 8''' | || '''Slide 8''' | ||
| + | |||
'''Assignment''' | '''Assignment''' | ||
| Line 207: | Line 215: | ||
Create alias names for gender and date of birth columns using different methods of aliasing. | Create alias names for gender and date of birth columns using different methods of aliasing. | ||
| − | + | ||
|| As an assignment, please do the following. | || As an assignment, please do the following. | ||
Latest revision as of 15:24, 28 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. Please download and extract the file. |
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 keyword.
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.
|
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. |