Iqra Technology SQL Training Day 6-1
Iqra Technology SQL Training Day 6-1
Iqra Technology SQL Training Day 6-1
Insert Into
Null values
Update
Delete
Insert Into
Insert Into:
In the first method there is no need to specify the column name where the data will be inserted, you need only
their values.
Let's take an example of table which has five records within it.
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (1, ABHIRAM, 22, ALLAHABAD);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (2, ALKA, 20, GHAZIABAD);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (3, DISHA, 21, VARANASI);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (4, ESHA, 21, DELHI);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (5, MANMEET, 23, JALANDHAR);
It will show the following table as the final result.
Insert Into:
You can create a record in CUSTOMERS table by using this syntax also.
INSERT INTO CUSTOMERS
VALUES (6, PRATIK, 24, KANPUR);
SQL NULL Values
What is a NULL Value?
A field with a NULL value is a field with no value.
If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then,
the field will be saved with a NULL value.
Note: A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been
left blank during record creation!
How to Test for NULL Values?
It is not possible to test for NULL values with comparison operators, such as =, <, or <>.
We will have to use the IS NULL and IS NOT NULL operators instead.
IS NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
Null values:
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
The IS NULL operator is used to test for empty values (NULL values).
The following SQL lists all customers with a NULL value in the "Address" field:
Null values:
The IS NOT NULL operator is used to test for non-empty values (NOT NULL values).
The following SQL lists all customers with a value in the "Address" field:
Update
Update:
SQL UPDATE
The SQL commands (UPDATE and DELETE) are used to modify the data that is already in the database. The SQL DELETE
command uses a WHERE clause.
SQL UPDATE statement is used to change the data of the records held by tables. Which rows is to be update, it is decided by a
condition. To specify condition, we use WHERE clause.
The UPDATE statement can be written in following form:
UPDATE table_name
SET column_name = expression
WHERE conditions
Let's take an example: here we are going to update an entry in the source table.
Update:
SQL statement:
UPDATE students
SET User_Name = 'beinghuman'
WHERE Student_Id = '3'
Update:
If you are going to update multiple fields, you should separate each field assignment with a comma.
UPDATE students
SET User_Name = 'beserious', First_Name = 'Johnny'
WHERE Student_Id = '3‘
Delete
Delete :
SQL DELETE
The SQL DELETE statement is used to delete rows from a table. Generally DELETE statement removes one or more records from a
table.
SQL DELETE Syntax
Let's see the Syntax for the SQL DELETE statement:
Delete :
Delete :
DELETE FROM EMPLOYEE;
Delete :
It will delete the all the records of EMPLOYEE table where ID is 101.
The WHERE clause in the SQL DELETE statement is optional and it identifies the rows in the column that gets deleted.
WHERE clause is used to prevent the deletion of all the rows in the table, If you don't use the WHERE clause you might loss all
the rows.
Q&A Session
Thanks.