Information System Management: Kamal Institute of Higher Education and Advance Technology Lab File
Information System Management: Kamal Institute of Higher Education and Advance Technology Lab File
Information System Management: Kamal Institute of Higher Education and Advance Technology Lab File
ADVANCE TECHNOLOGY
LAB FILE
MySQL
SQL Server
Oracle
dBASE
FoxPro
Structure Query Language
SQL Introduction
SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel
– (Structured English Query Language)”.
It is a query language used for accessing and modifying information in the database. IBM
first developed SQL in 1970s. Also it is an ANSI/ISO standard. It has become a Standard
Universal Language used by most of the relational database management systems
(RDBMS).
Some of the RDBMS systems are: Oracle, Microsoft SQL server, Sybase etc. Most of
these have provided their own implementation thus enhancing its feature and making it a
powerful tool.
Few of the SQL commands used in SQL programming are SELECT Statement, UPDATE
Statement, INSERT INTO Statement, DELETE Statement, WHERE Clause, ORDER BY
Clause,.
In a simple manner, SQL is a non-procedural, English-like language that processes data in
groups of records rather than one record at a time. Few functions of SQL are:
Store data
modify data
retrieve data
modify data
delete data
create tables and other database objects
delete data
WHY SQL?
USE OF SQL
1. CHAR: This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of
characters (i.e. the size) this data type can hold is 255 characters.
Syntax: CHAR (SIZE)
Example: CHAR (20)
2. VARCHAR: This data type is used to store variable length alphanumeric data. The
maximum this data type can hold is 4000 characters. One difference between this data type
and the CHAR data type is ORACLE compares VARCHAR values using non-padded
comparison semantics i.e. the inserted values will not be padded with spaces.
Syntax: VARCHAR (SIZE)
Example: VARCHAR (20) OR VARCHAR2 (20)
3. NUMBER: The NUMBER data type is used to store numbers (fixed or floating point).
Syntax: NUMBER (P, S)
Example: NUMBER (10, 2)
4. DATE: This data type is used to represent data and time. The standard format id DD-MM-
YY as in 13-Jul-15. To enter dates other than the standard format, use the appropriate
functions. Date Time stores date in the 24-hour format. By default, the time in a date field is
12:00:00 am, if no time portion is specified. The default date for a date field is the first day of
the current month.
Syntax: DATE
Create Database
To create a New Database, we use the SQL CREATE DATABASE statement.
Syntax:
CREATE DATABASE<Database name>;
Use Database
To use database, we use the SQL USE ‘Database name’ stamen
Syntax:
USE<DATABASE>;
Create a Table
To create a new table within a database, we use the SQL CREATE TABLE statement
Syntax:
CREATE TABLE <table name>
(
<Table element>,
<Table element>);
Syntax:
SQL DESC statement use for describe the list of column definitions for the specified table.
And it is used to describe a whole specified table.
SYNTAX:
DESC table name ;
SQL SELECT
Statement is used to view data from the table. This statement returns a list of table format
table data. Select return the data list from table with format. We use asterisk (*) sign to fetch
all table columns instead of writing all column names.
Syntax:
Select * from <table name>;
Retrieve some specific data.
Select <table element > from <table name> where <condition>
SYNTAX:
Delete
My SQL DELETE statement is used to delete data from the My SQL table within the
database. By using delete statement, we can delete records on the basis of conditions.
SYNTAX:
SYNTAX:
The NOT NULL constraint enforces a column to NOT accept NULL values.
The NOT NULL constraint enforces a field to always contain a value. This means that you
cannot insert a new record, or update a record without adding a value to this field.
SQL PRIMARY KEY Constraint applies on column(s) for uniquely identifies each record
(row) in the table.
SQL Primary Key constraint has been specified for certain column. We cannot enter
duplicate data in this column.
SQL Primary Key in a table has following three special attributes,
Constraint apply on column(s) for whose value must have reference in another table
column (that existing column must be primary key or unique key constraint).SQL
FOREIGN KEY constraints also known as relationship (referential) constraints
SYNTAX: Foreign key (table2 Column name) references table (column name)
COUNT:
Counts how many rows are in a particular column.
SYNTAX:
Select count (column name) from table name;
SUM:
Adds together all the values in a particular column.
SYNTAX:
Select sum (column name) as expression from table name;
AVG:
Calculates the average of a group of selected values.
SYNTAX:
Select avg (column name) as expression from table name;
MIN:
Return the lowest values in a particular column, respectively.
SYNTAX:
Select min (column name) from table name;
MAX:
Return the lowest and highest values in a particular column, respectively.
SYNTAX:
Select max (column name) from table name;
FIRST:
SYNTAX:
Select column name from table name limit1;
LAST:
SYNTAX:
Select column name from table name order by column name desc limit 1;
LOGICAL OPERATOR:
LIKE
SQL LIKE operator is used with WHERE clause to matches specific pattern in a column.
SQL LIKE condition applies on table column data.
Following two wildcards are often used with the LIKE operator
SQL BETWEEN operator used for fetching within range data. SQL BETWEEN query is
simply a shorthand way of expressing an inclusive range comparison.
SYNTAX:
Select*from table name where column name between value and value;
AND
SQL AND condition use to test more than one conditions INSERT, UPDATE, DELETE,
SELECT statement. AND operator work is test first condition if true come to a second and so
forth, otherwise not check
Next condition.
SYNTAX:
Select* from table name where column name condition value and column name condition
value ;)
OR
SQL OR Condition use to test more than one conditions in INSERT, UPDATE, DELETE,
SELECT statement. OR operator test all condition even if condition TRUE or FALSE. And
return data when
any one of the condition TRUE. SQL OR Operator same as AND operator, return the record
base filtered data. INSERT, UPDATE, DELETE, SELECT statement perform only one of the
specified
Condition TRUE.
SYNTAX:
(Select * from table name where column name condition value or column name condition
value ;)
IN
The My SQL IN condition is used to reduce the use of multiple OR conditions in a SELECT,
INSERT, UPDATE and DELETE statement
SYNTAX:
Select * from table name where column name in {values};
COMPARISON OPERATION
A comparison (or relational) operator is a mathematical symbol which is used to compare
two values.
Greater than
Less than
Greater than equal to
Less than equal to
Equal to
Not equal to
EQUALS TO:
SYNTAX:
SELECT * FROM table name WHERE column name = value;
GREATER THAN:
SYNTAX:
SELECT * FROM table name WHERE column name > value;
LESS THAN:
SYNTAX:
SELECT * FROM table name WHERE column name < value;
Inner join: