Professional Documents
Culture Documents
Introduction to RDBMS
Courses Table
CourseId Course
1 Basic SQL
2 Excel
CourseId Course
1 Basic SQL
Copyright © 2010 Pratian Technologies
2 Excel
www.pratian.com
Basic SQL
Relational DBMS - Properties
Entries of column and row values have to be single
valued
2 Radha 21 2
CourseId Course
1 SQL
2 Excel
Copyright © 2010 Pratian Technologies
www.pratian.com
Basic SQL
Summary
Understand database concepts
Introduction to SQL
Syntax
Name of the table must begin with a letter A-Z or a-z. It may
contain numerals and the special character _ (underscore)
Types of Constraints
UNIQUE
PRIMARY KEY
FOREIGN KEY
Example:
Example:
Example:
Example:
Example:
Syntax:
MODIFY clause
The MODIFY clause is used to modify existing columns of a table
DROP clause
DROP clause is used to remove columns or constraints from a
table
Example:
Data Manipulation
Syntax:
INSERT INTO table_name
[(col_name1, col_name2,…)]
{VALUES (value1, value2, …) | query };
Example:
INSERT INTO Courses (CourseId, Course)
VALUES (2, ‘EXCEL’);
Syntax:
UPDATE {table_name | alias}
SET col_name = value |
col_name = (SELECT Statement)
[WHERE Condition];
Syntax:
DELETE [FROM] {table_name | alias }
[WHERE Condition];
SELECT STATEMENT
SELECT STATEMENT
How to retrieve data from tables
Column aliases
Where clause
Pattern matching LIKE
SELECT STATEMENT - more options
Logical operators – AND, OR, NOT
IN
BETWEEN
IS NULL / IS NOT NULL
GROUP BY / ORDER BY
List of Operators
= Equal to
<> Not equal to
< Less than
> Greater than
<= Less than equal to
>= Greater than equal to
To list all students whose name begins with ‘K’ and third
letter ‘I’
SELECT Name
FROM Students
WHERE Name LIKE ‘K_I%’;
AND
SELECT Name FROM Students
WHERE StudentId > 1 AND JoinDate >= ‘2010-10-17’;
OR
SELECT Name FROM Students
WHERE Name = ‘Krishna’ OR StudentId = 2;
SELECT *
FROM Students
WHERE Name IN (‘Krishna’, ‘Radha’);
IS NULL
SELECT * FROM Students WHERE JoinDate IS NULL
IS NOT NULL
SELECT * FROM Students WHERE Name IS NOT NULL
Example:
SELECT * FROM Students
ORDER BY NAME