Module – 3 (SQL)
Module – 3 (SQL)
Technology
Moodbidri – 574225, Mangaluru, D.K
Module – 3 (SQL)
Dr. SANGAMESH C J
Professor
Dept. of information science &
Engg
YIT MOODABIDRI
SQL Data Definition and Data
Types
SQL uses the terms table, row, and column for the
attribute, respectively.
SQL command for data definition is the CREATE
and SMALLINT
Floating-point (real) numbers of various precision like
number of characters.
Bit-string data types
Fixed length n—BIT(n) or varying length— BIT
VARYING(n), where n is the maximum number of bits.
Another variable-length bit string data type called
BINARY LARGE OBJECT or BLOB is also available to
specify columns that have large binary values, such as
images.
Boolean data type
Values of TRUE or FALSE.
Syntax:
SELECT col1,col2,...colN FROM
table_name
WHERE [condition1] AND
[condition2]...AND[conditionN];
WHERE CLAUSE
To display all details of a student from
the PUC2 table whose marks is
greater than 210 and their COMB is
‘PCMC’.
SQL> SELECT * FROM PUC2
WHERE
REGNO
MARKS
NAME COMB
>210 and
MARKS
101 Anusha PCMC 363
COMB=‘PCMC’
WHERE CLAUSE [OR]
OR Operator – It is also used to
combine multiple conditions in
WHERE clause.
Syntax:
SELECT col1,col2,...colN FROM
table_name
WHERE [condition1] OR
[condition2]...OR[conditionN];
WHERE CLAUSE [OR]
To display all details of a student
from the
PUC2 table whose combination
COMB is
‘PCMC’ OR ‘PCME’
SQL> SELECT * FROM PUC2
WHERE
REGNO
101
COMB=‘PCMC’
NAME
Anusha
COMB
PCMC
MARKS
363
OR
COMB=‘PCME’
102 Chandan PCME 437
103 Bheemsen PCMC 117
104 Deeksha PCME 224
UPDATE OPERATION
•The update query is used to modify
the existing records in a table.
•If you considered the PUC2 table, the
modifications such as changes is the
REGNO,NAME,MARKS ,COMB can be
performed using WHERE clause with
UPDATE selected rows otherwise all the
rows would be affected.
UPDATE OPERATION
Syntax:
UPDATE TABLE table_Name
SET column1=value1,
column2=value2,
.
.
columnn=valuen,
[WHERE <condition>]
UPDATE OPERATION
•Logical operators such as AND or OR
also can be used to combine the
conditions.
UPDATE OPERATION
Following is an example, which would
add 5 marks to all students of PCMC
candidates.
SQL> UPDATE PUC2
SET MARKS= MARKS + 5
WHERE
REGNO COMB=‘PCMC’
NAME COMB MARKS
101 Anusha PCMC 368
102 Chandan PCME 437
103 Bheemsen PCMC 122
104 Deeksha PCME 224
105 Anu Pallavi PCMB 135
UPDATE OPERATION
Now there is a need to change the
combination as ‘PCMB’ for a student
whose register number is 104. It can be
changed as follows
Syntax:
DELETE FROM table_Name
[WHERE <condition>];
If you want to delete all the records from the PUC2 table, you
need not to use WHERE clause. The Delete query can be used as
follows:
SQL> DELETE FROM PUC2;
LIKE CLAUSE