Null values, insert, delete and update in database
Transcript of Null values, insert, delete and update in database
DATABASE MANAGEMENT
SYSTEMS (2130703)
AJAY THAKKAR (130110107001)
ANKIT KAPATEL (130110107011)
HEMANT SUTHAR (130110107058)
1
G H PATEL COLLEGE OF ENGG AND TECHNOLOGY
GUJARAT TECHNOLOGICAL UNIVERSITY
DEPARTMENT OF COMPUTER ENGINEERING
PREPARED BY:
FACULTY:
PROF.
CHINTAN
BHAVSAR
NULL VALUES, INSERT, DELETE AND UPDATE IN DATABASE
Definition - What does Null mean?
Null, in a database context, is the total absence of a value in a certain field and
means that the field value is unknown.
Null is not the same as a zero value for a numerical field, text field or space value.
Null implies that a database field value has not been stored.
EXPLAINATION:-
A null cannot be compared to a value. For example, if a query is directed to a
Customer_Addresses table to retrieve all customers without email addresses,
then the Structured Query Language (SQL) query cannot be written as follows:
SELECT * FROM Customer_ Addresses WHERE Email_Address=null.
Instead, so as not to introduce a comparison with a null, the query must be written
as follows: SELECT * FROM Customer_ Addresses WHERE Email_Address IS
null.
EXPLAINATION:-
When the values in a column containing nulls are counted, nulls are not included
in the results. For example, there are 200 customers in the Customer_ Addresses
table, and 30 have nulls in the Email_Address column. Doing a count using the
Email_Address column will return a result of 170.
Definition – What does Insert mean?
Insert is a widely-used command in the Structured Query Language (SQL) data
manipulation language (DML) used by SQL Server and Oracle relational
databases. The insert command is used for inserting one or more rows into a
database table with specified table column values. The first DML command
executed immediately after a table creation is the insert statement.
EXPLAINATION:-
A normal insert statement may be implemented in two forms:
INSERT INTO table_name VALUES (val1, val2, val3…). An example is: INSERT
INTO Employee VALUES (1, John, 23);
INSERT INTO table_name (column1, column2) VALUES (val1, val2, val3…). An
example is: INSERT INTO Employee (Eid, Name, Age) VALUES (1, John, 23);
EXPLAINATION:-
Column names identify columns that must be populated with specific values
determined by VALUES clause expressions. The number VALUES clause
values and names columns is the same. Table columns without specified
insert statement values are assigned default values.
DELETION:-
The command DELETE will delete records from a table. It will not delete specific
columns; it will delete an entire row.
Using the term DELETE FROM and then listing the table name will tell the
database from which table the records should be deleted.
If you want to delete select rows, you must also use the WHERE condition.
Otherwise, all of the records from the selected database will be deleted.
EXPLAINATION:-
The basic syntax for deleting records from a particular table using the WHERE
clause looks like this:
DELETE FROM include_table_name_here WHERE [what rows will be deleted];
Let’s assume you have a database named Employees. That database includes
their name, position, and salary. The list looks like this:-
EXPLAINATION:-
ID Name Position Salary
1 Hunter Manager 90000.00
2 Smith Assistant Manager 75000.00
3 Williams Sales Clerk 15000.00
If you want to DELETE all of the records from the database, you do not need to use the WHERE
clause. The following example would delete all of the records from the table named EMPLOYEES.
DELETE FROM Employees;
EXPLAINATION:-
Now, if you only wanted to DELETE the employee whose ID was number 2, you would include a
WHERE clause. The following example would delete only record number 2 from the table named
EMPLOYEES.
DELETE FROM Employees WHERE ID = 2;
UPDATION:-
UPDATE command used to modify fields of existing tuples.
WHERE clause is applied first and determines fields to be modified.
SET clause determines new values.
If field being modified is also used to determine new value, value on rhs is
old value.
UPDATION:-
The SQL UPDATE Statement
The UPDATE statement is used to update existing records in a table.
SQL UPDATE Syntax
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
UPDATION:-
SQL UPDATE Example
Assume we wish to update the customer "Alfreds Futterkiste" with a new contact
person and city.
-We use the following SQL statement:
-Example
-UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';