PostgreSQL-Database/C2/NULL-Values-and-UPDATE-Statement/English
Title of the Script: NULL Values and UPDATE Statement.
Author: Ketki Bhamble
Keywords: PostgreSQL, pgAdmin 4, Logical operators, AND, OR, NOT, WHERE, EduPyramids, video tutorial.
| Visual Cue | Narration |
| Slide 1
|
Welcome to this Spoken Tutorial on NULL Values and UPDATE Statement. |
| Slide 2
|
In this tutorial, we will learn how to,
|
| Slide 3
System Requirements
|
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:
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. | |
| Slide 6
What is a NULL Value? |
A null value is an unknown or missing value.
If a field has no value it can be left blank as no data stored in it. |
| Slide 7
Syntax of Null value SELECT column_names FROM table_name WHERE column_name IS NULL; |
This is the syntax to show a Null value.
IS NULL clause checks for fields that have no stored values. |
| I have opened the p g Admin 4 interface and connected to the localhost server. | |
| Type: INSERT INTO students (studentid, studentname, city, gender, dob, cgpa)
VALUES ('S116', 'Ravi', 'Pune', 'M', NULL, NULL); Click the Execute query icon. |
Let us insert a NULL value.For this, type the following query.
Here the NULL keyword is used to insert null values. Let us execute the query. The query is returned successfully. |
| Type: INSERT INTO students (studentid, studentname, city, gender)
VALUES ('S117', 'Kiran', 'Pune', 'M'); Click on the Execute query button. ADD ANNOTATION.( CGPA and DOB are automatically set to NULL) |
Type the following query and execute it. Here, C G P A and D O B columns are automatically set to NULL. |
| We can add a NULL value by inserting a record without specifying its value. | |
| Type: SELECT * FROM students
WHERE cgpa IS NULL; |
Type the following query.
Here we are using the IS NULL clause. Let us execute the query. The output displays details of students whose C G P A is currently not recorded. |
| Here, the D O B and C G P A values are not known. | |
| Now let us see another example. | |
| Type: SELECT studentid, studentname
FROM students WHERE cgpa IS NULL; Click on the Execute query button. |
Type the following query and execute it. This query displays studentid and their names whose C G P A value is NULL. |
| Let us update the record so that it no longer displays NULL. | |
| Slide 8
UPDATE Statement |
UPDATE Statement is used to modify existing records in a table. |
| Slide 9
Syntax of UPDATE Statement. UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; |
Here is the syntax of the UPDATE statement.UPDATE specifies the table to be modified.
SET assigns new values to one or more columns. WHERE selects the records that need to be updated. |
| Type: UPDATE students
SET cgpa = 8.1 WHERE studentid = 'S116'; Click on the Execute query button. |
Let us update the Null value.
Type this query. Here the SET keyword sets the C G P A value to 8 point 1. Let us execute the query. |
| Cursor on Query returned successfully in 322 msec. | The output shows that the query is updated. |
| Type:
SELECT * FROM students WHERE studentid = ‘S116’; |
Now let us type this query and execute it.
We can see that a new record is added to the table. |
| Show the table and point to M in the records. | Let us update the records of students with studentids S116 and S117 |
| Type the following:UPDATE students
SET gender = 'Male' WHERE studentid = 'S116' OR studentid = 'S117'; Click on the Execute Query button. |
Type the following query.
In this query we will set the gender to male. Let us execute the query. The table is now updated. |
| Type: SELECT * FROM students;
Click on the Execute Query button. Point to the gender columns of the students. |
Let us display the entire table.Type this query and execute it.
We can see that in the gender column M is updated to Male for studentids S116 and S117. |
| Slide 10
Summary In this tutorial, we have learnt how to,
|
With this, we come to the end of this tutorial.
Let us summarise. |
| Slide 11
Assignment As an Assignment, Insert a student record with a NULL CGPA value. Update the NULL CGPA value for one student. Verify the updated record using a SELECT query. |
We encourage you to do this assignment. |
| Slide 12
Thank you This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited SINE IIT Bombay. |
Thank you for joining. |