You are on page 1of 7

Chapter 9

Structured Query Language


SQL is a language designed for RDBMS കകൈകൈകാരരര്യം ചചെയകാനനുപയയകാഗഗികനുന
communicating with a database for കൈമരമ്പ്യൂട്ടര്‍ ഭകാഷയകാണണ് SQL
implementing RDBMS.
Features of SQL

• It is a relational database language not a • ഇചതകാരനു യപകാഗകാമഗിങണ് ഭകാഷയല


programming language. • ഇതണ് ലഘനുവനുര്യം ശക്തവനുമകാണണ്
• It is simple and powerful. • യഡേറകായബേസഗില്‍ create, update, delete,
• It allows the user to create, update, delete, retrieve data എനഗിവ സകാധരമകാണണ്
and retrieve data from a database.
Components of SQL
Data Defnition Language( DDL)
DDL commands are used to create, modify യഡേറകായബേസണ് നഗിര്‍മഗികകാനനുര്യം മകാറര്യം വരനുതകാനനുര്യം
and remove database objects. DDL ഒഴഗിവകാകകാനനുമനുള്ള കൈമകാനനുകൈളകാണണ് DDL commands.
commands are CREATE, ALTER and DROP. CREATE, ALTER, DROP എനഗിവയകാണണ് കൈമകാനനുകൈള
Data Manipulation Language( DML)
DML is a component of SQL used to interact യഡേറകാചയ കകൈകൈകാരരര്യം ചചെയകാനനുള്ള കൈമകാനനുകൈളകാണണ്
with database. DML commands are SELECT, DML. SELECT, INSERT, UPDATE, DELETE
INSERT, UPDATE and DELETE. എനഗിവയകാണണ് കൈമകാനനുകൈള
Data Control Language( DCL)
DCL is used to control access to database. യഡേറകായബേസഗിചന നഗിയനഗികകാനനുള്ള കൈമകാനനുകൈളകാണണ്
DCL commands are GRANT, COMMIT, DCL. GRANT, COMMIT, ROLLBACK, REVOKE
ROLLBACK and REVOKE. എനഗിവയകാണണ് കൈമകാനനുകൈള
MySQL
MySQL is an is an open-source relational Open-source അധഗിഷഗിത relational database
database management system (RDBMS). The management system (RDBMS) ആണണ് MySQL.
main features of SQL are ഇതഗിചന സവഗിയശഷതകൈള
• open source license. • open source license.
• It is portable and works with many • PHP, PERL, C, C++, JAVA തനുടങഗിയ
languages such as PHP, PERL, C, C++, JAVA ഭകാഷകൈയളകാചടകാപര്യം ഉപയയകാഗഗികകാര്യം
etc. • web applications നഗിര്‍മഗികകാര്യം
• It is used for web applications. • LAMP open source web application
• It is a central component of the widely software ചല പധകാന ഭകാഗമകാണണ്.
used LAMP open source web application
software.
MySQL Commands
Creating a database
A database in MYSQL is created using the MYSQL ല ഡഡററഡബസസ നനരമനകറന CREATE
CREATE DATABASE command. The syntax is
CREATE DATABASE <Database Name> ; DATABASE command ഉപഡയറഗനകകനക.
CREATE DATABASE <Database Name>;
Opening a database
A database can be using the USE command. യഡേറകായബേസണ് ഉപയയകാഗക്ഷമമകാകനുവകാന്‍ USE കൈമകാനണ്
A database becomes active when we opens ഉപയയകാഗഗികനുനനു.
it. The syntax is USE <Database_Name> ;
USE <Database_Name> ;
The SHOW command is used to check the Database, table എനഗിവയനുചട പട്ടഗികൈ കൈകാണഗികനുവകാന്‍
existence of a database or table. The Syntax SHOW കൈമകാനണ് ഉപയയകാഗഗികനുനനു.
is SHOW DATABASES;
SHOW DATABASES; SHOW TABLES;
SHOW TABLES;
Data types in SQL
Numeric data type
INT( INTEGERS) data type
Integers are represented in My SQL by INT INT ഉപയയകാഗഗിചണ് ദശകാര്യംശമഗിലകാത പമ്പ്യൂര്‍ണ്ണസര്യംഖരകൈചള
data type. They are whole numbers ie, ഉളചപടനുതകാര്യം
without fractional part. ഉദകാ - INT(3) – 3 അകങളനുള്ള സര്യംഖര
Eg: INT(3) – Integer with 3 digits
DEC ( DECIMAL) data type
The DEC data type represents fractions. ഭഗിനസര്യംഖരകൈചള ഉളചപടനുതനുവകാന്‍ DEC(Size,Scale),
Numbers. The syntax is DEC(Size,Scale), where ഉപയയകാഗഗികനുനനു. Size ആചകൈയനുള്ള അകങചളയനുര്യം
Size is the total number of digits and scale is ,Scale ദശകാര്യംശതഗിനനുയശഷമനുള്ള അകങചളയനുര്യം
the number of digits after the decimal point. സമ്പ്യൂചെഗിപഗികനുനനു.
For example DEC(5,2), where the total number ഉദകാ - DEC(5,2) – ആചകൈ അകങള 5 ദശകാര്യംശര്യം
of digits is 5 and the number of digits after കൈഴഗിഞണ് 2.
the decimal point will be 2.
String data types
A string is a group of characters. ഒരനുകൈമ്പ്യൂട്ടര്യം കൈരകാരക്ടറനുകൈളകാണണ് string
1) CHAR( CHARACTER) data type
Character includes letters, digits, special അക്ഷരങളനുര്യം അകങളനുര്യം ചെഗിഹ്നങളനുര്യം
symbols etc. It is a fxed length data type. ഉളചപടനുനതകാണണ് CHAR. ഇതഗിചന വലഗിപര്യം
The syntax is CHAR(Size) where Size സഗിരമകായഗിരഗികനുര്യം. CHAR(Size) എനകാണണ്
represent the maximum number of ഇതനുപയയകാഗഗികനുനതണ്. Size ഉപയയകാഗഗികനുന
characters. The default size of CHAR data കൈരകാരക്ടറനുകൈളനുചട എണ്ണചത സമ്പ്യൂചെഗിപഗികനുനനു.
type is 1.
2) VARCHAR data type
The VARCHAR data type represent variable VARCHAR അക്ഷരങളനുര്യം അകങളനുര്യം ചെഗിഹ്നങളനുര്യം
length strings. It is similar to CHAR data type ഉളചപടനുനനു. VARCHAR(Size) എനകാണണ്
but only allocates memory according to the ഇതനുപയയകാഗഗികനുനതണ്. Size ആവശരമനുള്ള
size of the string. It saves memory space. കൈരകാരക്ടറനുകൈളനുചട എണ്ണചത സമ്പ്യൂചെഗിപഗികനുനനു. പയക്ഷ
മനുഴനുവന്‍ സലവനുര്യം ഉപയയകാഗഗികനുനഗില.
Date and Time data type
1)Date data type:-The date data type is used 1)Date data type:- YYYY-MM-DD format ല്‍
for storing date. The date in MySQL is തതീയതഗി സമ്പ്യൂക്ഷഗികനുവകാനനുപയയകാഗഗികനുനനു.
represented in YYYY-MM-DD format (Standard 2)Time data type:- HH:MM:SS format ല്‍ സമയര്യം
format). സമ്പ്യൂക്ഷഗികനുവകാന്‍ ഉപയയകാഗഗികനുനനു.
2)Time data type:-The time data type is used
for storing time.The format is HH:MM:SS.
SQL commands
DDL Commands:-DDL command deals with DDL Commands:-DDL command database ചന
structure of database. It consists of three ഘടനയനുമകായഗി ബേന്ധചപട്ടണ് നഗില്‍കനുനനു. CREATE,
commands CREATE, ALTER and DROP. ALTER and DROP എനഗിവയകാണണ് കൈമകാനനുകൈള
CREATE TABLE Command
The CREATE TABLE Command is used to The CREATE TABLE Command table (relation)
create a table(relation). The syntax is നഗിര്‍മഗികകാന്‍ ഉപയയകാഗഗികനുനനു. syntax
CREATE TABLE <TableName> CREATE TABLE <TableName>
(<ColumnName1> (<ColumnName1>
<DataType> [<Constraints>] , <ColumnName2> <DataType> [<Constraints>] , <ColumnName2>
<DataType> [<Constraints>] ,...................................... ); <DataType> [<Constraints>] ,...................................... );
TableName - the name of the table TableName – table ചന യപരണ്
ColumnName - name of the column ColumnName – യകൈകാളതഗിചന യപരണ്.
Constraint – Condition (check) applied to a Constraint – ഒയനകാ അതഗിലധഗികൈയമകാ യകൈകാളങചള
column or group of columns. നഗിയനഗികനുനനു
Example:-CREATE TABLE STUDENT( ROLLNO Example:-CREATE TABLE STUDENT( ROLLNO
INT,NAME INT,NAME
VARCHAR(20),TOTAL_MARK INT,PERCENTAGE VARCHAR(20),TOTAL_MARK INT,PERCENTAGE
DEC(5,2) ); DEC(5,2) );
Rules for naming a table
1. The name must not be an SQL keyword. • SQL keyword ആകൈകാന്‍ പകാടഗില
2. The name must begin with alplabets(A-Z • alplabet ല്‍ (A-Z or a-z) തനുടങണര്യം.
or a-z). • അക്ഷരര്യം, അകര്യം, ,under score( _ ), dollar ($)
3. The name may contain a character,under എനഗിവ ഉളചപടനുതകാര്യം
score( _ ) and dollar ($) sign.
• നഗിലവഗിലമ്പ്യൂള്ള table ചന യപരണ് ആകൈകാന്‍ പകാടഗില
4. The name should not be the name of an
existing table(duplicate). • white space, special symbols എനഗിവ പകാടഗില
5. The name of the table must not contain
white space,special symbols.
Constraints
A constraint is a condition applied to a ഒയനകാ അതഗിലധഗികൈയമകാ യകൈകാളങളനുചട മമ്പ്യൂലരര്യം
column or group of columns. Constraints are നഗിയനഗികകാനനുള്ളതകാണണ് constraint. ഇതണ് Table
classifed into Table Constraints and Column Constraint, Column Constraint എനണ് രണകായഗി
Constraints. A table constraint is applied to a തഗിരഗിചഗിരഗികനുനനു. Table Constraint കൈള Table ചന
table where as a column constraint is applied മനുഴനുവനകായനുര്യം Column Constraint കൈള Column
to a column. Constraints ensure the database മകാത്രമകായനുര്യം നഗിയനഗികനുനനു.
integrity hence they are also called database column constraints
integrity constraints. • NOT NULL:- NULL value ഇല എനണ് ഉറപണ്
column constraints വരനുതനുനനു.
• NOT NULL:- This constraint ensures that a • AUTO_INCREMENT:- പയതരകൈ യകൈകാളതഗിചല
column can never have NULL(empty) മമ്പ്യൂലരര്യം തനഗിചയ വര്‍ദഗിപഗികനുനനു. ഇതണ് primary
values. key ആയഗിരഗികണര്യം. ഒരനു യകൈകാളര്യം മകാത്രയമ
• AUTO_INCREMENT:- it automatically ഇതരതഗില്‍ അനനുവദഗികമ്പ്യൂ. 1 മനുതല്‍ ഇതഗിചന
assigns a series of number and insert it to മമ്പ്യൂലരങള ആരര്യംഭഗികനുനനു.
column. The default starting value is 1. The • UNIQUE:- പയതരകൈ യകൈകാളണ്തഗിചല രണണ് വരഗികൈളകണ്
auto increment column must be defned as ഒയര മമ്പ്യൂലരര്യം വരനുനതണ് തടയനുനനു.
primary key of the table. Only one • DEFAULT:- ഒരനു യകൈകാളതഗില്‍ പയതരകൈ മമ്പ്യൂലരര്യം
auto_increment column is allowed in a വരകാന്‍ സഹകായഗികനുനനു.
table. Table Constraints
• UNIQUE:-This constraint ensures that no • PRIMARY KEY:- ഒരനു യകൈകാളചത PRIMARY KEY
two rows have the same value in a ആകനുനനു.
specifed column. • CHECK:- ഒരനു യകൈകാളതഗില്‍ വരകാവനുന മമ്പ്യൂലരങചള
• DEFAULT:-This constraint is used to specify നഗിയനഗികനുനനു.
a default value for a column.
Table Constraints
• PRIMARY KEY:-It declares a column as the
primary key of a table. The primary key
cannot contain NULL value
• CHECK:-This constraint limits the values
that can be inserted into a column of a
table.
DESC or DESCRIBE Command
The DESC or DESCRIBE Command is used DESC or DESCRIBE Command ഉപയയകാഗഗിചണ്
view(display) the structure of a table. table ചന ഘടന കൈകാണകാര്യം
DML Commands
Data Manipulation Language (DML) ഡഡററഡബസനലല ഡഡററലയ കകകറരസയയ
commands are used for manipulating data in
database. ലചയസയറന DML കമറനകകള ഉപഡയറഗനകകനക.
INSERT INTO Command
This command is used to insert a row(tuple) Table യലയണ് ഒയനകാ അതഗിലധകൈയമകാ വരഗികൈള
into a table. The syntax is: യചെര്‍കനുവകാന്‍ INSERT INTO കൈമകാനണ്
INSERT INTO <TABLENAME> ഉപയയകാഗഗികനുനനു.syntax:
VALUES(<Value1>,<Value2>,.... ); INSERT INTO <TABLENAME>
Example:- VALUES(<Value1>,<Value2>,.... );
• INSERT INTO STUDENT VALUES Example:-
(1106,’ANISH’,599); • INSERT INTO STUDENT VALUES
• INSERT INTO STUDENT (1106,’ANISH’,599);
(ROLLNO,NAME,TOTALMARK) VALUES • INSERT INTO STUDENT
(1106,’ANISH’,599); (ROLLNO,NAME,TOTALMARK) VALUES
• STUDENT (ROLLNO,NAME,TOTALMARK) (1106,’ANISH’,599);
VALUES (1106,’ANISH’,599), (1109,’ANUJ’,514); • STUDENT (ROLLNO,NAME,TOTALMARK)
• The above command creates two rows into VALUES (1106,’ANISH’,599), (1109,’ANUJ’,514);
the table STUDENT. • മനുകൈളഗില്‍ തനഗിരഗികനുന command രണണ് rows
STUDENT table ല്‍ യചെര്‍കനുനനു.
SELECT Command
The SELECT Command is used to select rows Table ല്‍ ഉളചപട്ടഗിരഗികനുന record കൈചള
(tuples or record) from a table. The syntax is എടനുകകാനനുള്ള കൈമകാനകാണണ് SELECT.
SELECT <ColumnName1>,[<ColumnName2>,.... ] SELECT <ColumnName1>,[<ColumnName2>,.... ]
FROM <TableName> ; FROM <TableName> ; എന വഗിധതഗിലകാണണ് ഈ
Example:-SELECT ROLLNO,NAME,TOTALMARK കൈമകാനണ് ഉപയയകാഗഗികനുനതണ്.
from STUDENT ; SELECT * FROM <TableName> ; എന കൈമകാനണ്
The output is എലകാ യകൈകാളങചളയനുര്യം എടനുതനുകൈകാണഗികനുനനു.
ROLLNO NAME TOTALMARK
1106 ANISH 599
1109 ANUJ 514
Note:-To select all columns instead of column
name asterisk(*) can be used .
Example :-SELECT * FROM STUDENT ;
The DISTINCT Keyword
The Keyword DISTINCT is used to avoid SELECT കൈമകാനഗിചന ഫലതഗിചല ആവര്‍തനര്യം
duplicate rows from the result of a select ഒഴഗിവകാകകാന്‍ DISTINCT എന വകാകണ്
command. ഉപയയകാഗഗികനുനനു.
The keyword ALL is used to display duplicate SELECT കൈമകാനഗിചന ഫലതഗിചല ആവര്‍തനര്യം
rows in a select command. ഉളചപടനുതകാന്‍ ALL എന വകാകണ് ഉപയയകാഗഗികനുനനു.
WHERE Clause
The WHERE clause is used to select rows or പയതരകൈ കൈണതീഷന്‍ അനനുസരഗികനുന റഗിയകകാര്‍ഡേനുകൈചള
columns from a table which satisfy a specifc കൈചണതകാന്‍ WHERE ഉപയയകാഗഗികനുനനു.
condition. The Syntax is കൈണതീഷനനുകൈള രമ്പ്യൂപഗികൈരഗികകാന്‍ റഗിയലഷനല്‍
SELECT <Columnname>,[<ColumnName>,.....] ഓപയറററനുകൈള ഉപയയകാഗഗികനുനനു.
FROM <TableName> WHERE <Condition> ;
The conditions can be expressed with the
help of relational operators. The list of
operators used in SQL are >, >=, <,<=,=,<>
The Like keyword
The Like keyword is used to search for a specifed pattern in a column.
Examples:-
• Select * from STUDENT where place=’kannur’;
• Selects all from student table whose place is equal to ‘kannur’
• Select * from STUDENT where name like ‘A%’;
• Selects all from student table whose Name start with A, (% replace for any number of
characters).
• Select * from STUDENT where name like ‘%m’;
• Selects all from student table whose name end with m
• Select * from STUDENT where name like ‘%la%’;
• Selects all from student table whose name contains la.
പയതരകൈ പകായറണ്‍ കൈചണതകാന്‍ LIKE ഉപയയകാഗഗികനുനനു.
BETWEEN ............ AND Operator
The BETWEEN ............. AND operator is used to specify a range .
BETWEEN ............. AND ഉപയയകാഗഗിചണ് തനുടര്‍ചയകായനുള്ള ചെഗില ചസറണ് കൈണനുപഗിടഗികകാര്യം
Example:-
• Select * from STUDENT where mark1 between 40 and 50;
• Selects all from student table whose mark in between 40 and 50
• Select * from STUDENT where mark1 not between 20 and 35;
• Selects all from student table whose mark is not in between 20 and 35
The IN Operator
The IN operator is used for setting a condition satisfying any list of values.
IN ഉപയയകാഗഗിചണ് ചതരചഞടനുകചപട്ടണ് ചസറണ് കൈണനുപഗിടഗികകാര്യം
Example:-
• SELECT Name,Total_Mark FROM STUDENT WHERE COURSE IN (‘COMMERCE’,’HUMANITIES’) ;
• Displays name,totalmark of all students studying in either Commerce or Humanities.
IS NULL Operator
The SQL NULL is the term used to represent a missing value. The IS NULL operator in a
WHERE clause to fnd rows containing a null value in a particular column.
Example:-
SELECT * FROM STUDENT WHERE Course IS NULL ;
Display details of students whose course is not specifed.
ശമ്പ്യൂനരമകായഗികഗിടകനുന ചെഗില യകൈകാളങള കൈണനുപഗിടഗികകാന്‍ IS NULL ഉപയയഗഗികനുനനു.
ORDER BY Clause
The ORDER BY clause is used to sort the ഒയനകാ രയണകാ യകൈകാളങചള അടഗിസകാനചപടനുതഗി
result of a select statement in ascending or ascending അചലങഗില്‍ descending order ല്‍
descending order. The default order is ലഭഗികനുവകാന്‍ ORDER BY ഉപയയകാഗഗികനുനനു.
ascending. The ascending order is specifed സകാധകാരണയകായഗി ascending order ലകാണണ്
by the ASC keyword and descending order by കൈകാണനുനതണ്. descending order ല്‍ കൈകാണകാന്‍
DESC keyword. DESC ഉപയയകാഗഗികനുനനു. ASC ഉപയയകാഗഗിചകാല്‍
ascending order ല്‍ കൈകാണകാര്യം
COUNT ( ) Function
The COUNT() function returns the number of rows that matches a specifed condition. The
COUNT(*) function returns the number of records in a table.
Example:
SELECT COUNT(*) from Student ;
Display the total number of Students in the Students table.
പയതരകൈ കൈണതീഷന്‍ അനനുസരഗിചനുള്ള മമ്പ്യൂലരങളനുചട എണ്ണര്യം കൈണനുപഗിടഗികകാന്‍ COUNT() ഉപയയകാഗഗികനുനനു. പയതരകൈ
കൈണതീഷന്‍ അനനുസരഗിചനുള്ള റഗിയകകാര്‍ഡേനുകൈളനുചട എണ്ണര്യം കൈണനുപഗിടഗികകാന്‍ COUNT(*) ഉപയയകാഗഗികനുനനു.
GROUP BY Clause
The GROUP BY clause is used to group the rows of a table based on a common value.
Example:-
SELECT Course,COUNT(*) FROM STUDENT GROUP BY Course
Display each Course and Number of Students in each Course.
ചപകാതനുമമ്പ്യൂലരര്യം അനനുസരഗിചണ് യകൈകാളങചള ഒനഗിപഗികനുവകാന്‍ GROUP BY ഉപയയകാഗഗികനുനനു.
Aggregate Functions
The aggregate functions acts on a group of data and returns a single data. They are also
called summary functions.
Commonly used aggregate functions
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the frst value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
ഒരനു യകൈകാളതഗിചല മമ്പ്യൂലരങചള ഒനകായഗി പരഗിഗണഗിചണ് ചപകാതനുവകായ മമ്പ്യൂലരര്യം കൈകാണകാന്‍ aggregate function
ഉപയയകാഗഗികനുനനു.
Changing the structure of a table
The structure of a table can be changed by using DDL Commands. It includes adding or
removing columns, Changing data type and size of existing columns, renaming table etc.
ഒരനു table ചന ഘടന മകാറകാന്‍ സകാധഗികനുനതകാണണ്. പനുതഗിയ യകൈകാളങള യചെര്‍കകാനനുര്യം ഉള്ളതണ് ഒഴഗിവകാകകാനനുര്യം യപരണ്
മകാറകാനനുര്യം യഡേറകായനുചട തരവനുര്യം വലഗിപവനുര്യം മകാറകാനനുര്യം കൈഴഗിയനുര്യം
ALTER TABLE Command
The ALTER TABLE Command is used to change table structure.
Adding New Column
• ALTER TABLE <TableName> ADD (<ColumnName> <NewDataType> [(<Size>)]
<ColumnConstraint> );
• Example:- ALTER TABLE STUDENT ADD (Grade CHAR(2) );
• To add a new column Grade to the table STUDENT .
Modifying Existing column
• ALTER TABLE <TableName> MODIFY (<ColumnName> <NewDataType> [(<NewSize>)]) ;
Removing column from a table
• ALTER TABLE <TableName> DROP <ColumnName> ;
• Example:-ALTER TABLE STUDENT DROP Total_Mark ;
• To remove the column Total_Mark from the table STUDENT.
Renaming a table
• ALTER TABLE <TableName> RENAME TO <New_Table_Name> ;
• Example:- ALTER TABLE STUDENT RENAME TO STU;
• To rename STUDENT table to STU.
Deleting rows from a table
The DELETE command can be used to remove individual rows from a table.
The Syntax is:
DELETE FROM <Table_Name> [ WHERE <condition>] ;
Example:-DELETE FROM STUDENT Where RollNO=1109 ;
To remove the details of student with RollNo 1109.
DELETE command ഉപയയകാഗഗിചണ് ഒരനു table ചല റഗിയകകാര്‍ഡേനുകൈചള ഒഴഗിവകാകകാര്യം
UPDATE Command
The UPDATE command is used to change the values in a column of specifed rows. The rows
are set to new values using the SET keyword. The syntax is:
UPDATE <TableName> SET <ColumnName> =<value>[,<ColumnName>=<value> .... ] [ Where
<Condition> ];
Example:-
UPDATE STUDENT SET ROLLNO=1114 WHERE Name=’Manu’ ;
To change the rollno of a student named Manu from the table student.
UPDATE command ഉപയയകാഗഗിചണ് ഒരനു table ചല റഗിയകകാര്‍ഡേനുകൈളകണ് ആവശരമകായ മകാറര്യം വരനുതകാര്യം.
Removing table from a database
A table can be removed from a database by using the DROP TABLE Command. It is a DDL
which permanently removes table from the database.The syntax is
DROP TABLE <TableName> ;
Example:-
DROP TABLE STUDENT;
To remove the table STUDENT from the table.
DROP TABLE Command ഉപയയകാഗഗിചണ് യഡേറകായബേസഗില്‍നഗിനനുര്യം table ചന മനുഴനുവനകായഗി ഒഴഗിവകാകകാര്യം
Nested Queries
A Nested query is a query placed within another SQL query. The query that contains the
subquery is called outer query and the inner query is called subquery. The inner query is
evaluated frst and then the outer query is evaluated.
Example:-
UPDATE STUDENT SET Total_Mark=Total_Mark + 25 WHERE AGE IN (SELECT AGE
FROM STUDENT WHERE AGE >=21 ) ;
Update Total_Mark by 25 marks in Students table for all students whose age is greater
than or equal to 27.
ഒരനു query യനുചട ഉള്ളഗില്‍ മചറകാരനു query വയനുനതകാണണ് nested query. ഇവഗിചട അകൈതനുള്ള query ആദരര്യം
പവര്‍തഗിചണ് അതഗിചന ഫലതഗിനനനുസരഗിചണ് പനുറയമയനുള്ള query കൈള പവര്‍തഗികനുനനു.
Concept of Views
A view is a virtual table which is derived from ഒയനകാ അതഗിലധഗികൈയമകാ table ല്‍ നഗിനനുര്യം കൈചണതനുന
an existing table(Base table). The CREATE സകാങല്‍പഗികൈ table ആണണ് view.
VIEW Command is used to create a VIEW. The
Syntax is Advantages of View are
CREATE VIEW <View_Name> AS SELECT • table ലന സകരക വരദനപനകറന കഴനയകനക.
<ColumnName1> [,<ColumnName2>,...... ]
FROM <TableName> [Where <Condition> ] ; • ഒരക ഡഡററലയ പല വനധതനല കറണറന
Example:- കഴനയകനക.
CREATE VIEW Student1 AS SELECT * FROM
• സങതീര്‍ണ്ണത ഒളഗിപഗികകാന്‍ കൈഴഗിയനുനനു.
STUDENT Where Course=’Science ‘ ;
The DROP VIEW Command can be used to
remove view
Advantages of View are
• Views allows to setup diferent security
levels for a table.
• Views allows to see the same data in a
diferent way.
• It helps to hide complexity.

You might also like