Difference between revisions of "PostgreSQL-Database/C2/Alter-Table-Statement/English"
(Created page with "'''Title of the Script: Alter Table Statement'''. '''Author: EduPyramids''' '''Keywords: '''PostgreSQL, pgAdmin4, Alter Table, add marks, numeric type, EduPyramids, video t...") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 4: | Line 4: | ||
| − | '''Keywords | + | '''Keywords''': PostgreSQL, pgAdmin4, Alter Table, add marks, Numeric datatype, syntax, RENAME COLUMN, EduPyramids, video tutorial. |
| Line 31: | Line 31: | ||
* '''PostgreSQL version 18.1''', and | * '''PostgreSQL version 18.1''', and | ||
* '''PgAdmin4 version 9.11'''. | * '''PgAdmin4 version 9.11'''. | ||
| + | |||
| + | EduPyramids periodically verifies the correctness of the tutorials for subsequent versions. | ||
| + | |||
| + | Changes, if any, are explained through the Instruction Sheet. | ||
| Line 38: | Line 42: | ||
'''Pre-requisites ''' | '''Pre-requisites ''' | ||
| + | |||
| + | To follow this tutorial, | ||
| + | * Learners should have '''PostgreSQL''' and '''pgAdmin4 ''' | ||
| + | * For the prerequisite '''PostgreSQL''' tutorials, please visit | ||
[https://edupyramids.org/ https://EduPyramids.org] ''' | [https://edupyramids.org/ https://EduPyramids.org] ''' | ||
Latest revision as of 11:52, 11 May 2026
Title of the Script: Alter Table Statement.
Author: EduPyramids
Keywords: PostgreSQL, pgAdmin4, Alter Table, add marks, Numeric datatype, syntax, RENAME COLUMN, EduPyramids, video tutorial.
| Visual Cue | Narration |
| Slide 1
Title Slide |
Welcome to this Spoken Tutorial on Alter Table Statement in PostgreSQL. |
| Slide 2
Learning Objectives |
In this tutorial, we will learn about:
|
| Slide 3
System Requirements
EduPyramids periodically verifies the correctness of the tutorials for subsequent versions. Changes, if any, are explained through the Instruction Sheet.
|
To record this tutorial, I am using the following setup. |
| Slide 4
Pre-requisites To follow this tutorial,
|
To follow this tutorial,
|
| Slide 5
Code Files The following code file is required to practice this tutorial:
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 learn about the Alter table. | |
| Slide 5
Alter Table |
ALTER TABLE is used to modify the structure of an existing table.
It can add, delete, or modify columns. It is used to add or remove constraints. |
| Slide 6
Syntax of Alter Table statement ALTER TABLE table_name ADD column_name datatype; |
This is the syntax of the Alter table statement to add a column. |
| Let us understand with an example. | |
| Show pgAdmin 4 interface | I have opened the pgAdmin 4 interface and connected to the localhost server. |
| Type:
SELECT * FROM students;
Highlight: student ID, name, city, gender, date of birth, and CGPA. |
This is the students table with its current columns.
Now, we will add new columns to store subject marks. |
| To add a new column, we will use the ALTER TABLE statement. | |
| Type:
ADD Maths NUMERIC, ADD English NUMERIC; Click on the Execute query button. |
Let's type the following query.
In this query we will add two columns Maths and English with Numeric data type. Click on the Execute query icon. The table now has two new columns Maths and English. |
| Type:
SELECT * FROM students; Click on the Execute query button. |
To see the added columns type this query.
Let us execute the query..
|
| Copy and paste from code file:
UPDATE students AS s SET maths = v.maths, english = v.english FROM (VALUES ('S101',72,75), ('S102',88,91), ('S103',69,73), ('S104',85,87), ('S105',64,70), ('S106',92,95), ('S107',78,81), ('S108',86,89), ('S109',71,74), ('S110',83,85), ('S111',67,69), ('S112',90,93), ('S113',76,80), ('S114',82,84), ('S115',68,72), ('S116',74,77), ('S117',89,92) ) AS v(studentid, maths, english) WHERE s.studentid = v.studentid; Click on the Execute Query button on the tool bar. |
Let us copy and paste this query from the code file into the query window.
Let us add marks to the Maths and English columns of the students table. We will use the UPDATE statement to populate marks for the existing student records. Let us execute the query. |
| Type:
ALTER TABLE students RENAME COLUMN dob TO date_of_birth; Highlight output. |
Now let us see how to modify a column name.
Type this query.This query changes the column name from dob to date of birth. Let us execute the query. The column name is modified successfully. |
| Type:
SELECT * FROM students; Click on the Execute query button. |
To see the inserted marks and change in column name, type this query.
Let us execute it.
|
| Slide 7
Summary In this tutorial, we have learnt about,
|
With this we come to the end of this tutorial.
Let us summarise. |
| Slide 8
Assignment As an assignment,
|
We encourage you to try this assignment. |
| Slide 9
This Spoken Tutorial is brought to you by EduPyramids Educational Services Private limited SINE IIT Bombay. |
Thank you for joining. |