0% found this document useful (0 votes)
13 views

Structured Query Language

SQL notes for class 12 very helpful

Uploaded by

mehekmaurya05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Structured Query Language

SQL notes for class 12 very helpful

Uploaded by

mehekmaurya05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SIMPLE QUERIES IN SQL

Structured Query Language (SQL)

Introduction
SQL, Structured Query Languages, was developed in 1970’s in IBM
Laboratory. It is used for accessing and manipulating databases. SQL
commands are used to create, transform and retrieve information
from Relational Database Management System and are also used for to
create interface between a user and database. By using SQL
commands, one can search for any data in the database and perform
other functions like creating, adding records, modifying data, removing
rows, dropping tables etc.

Features of SQL
It can retrieve data from a database through Query processing
It can insert records in a database.
It can update records in a database.
It can create a new database and modify the existing ones.
It can create new tables in database.
It can create view in database.

Classification of SQL statements

By: Ritu Pandey PGT(Computer Science)


SIMPLE QUERIES IN SQL

SQL statements

Data Definition Transaction Control


Language (DDL) Language (TCL)

Data Manipulation Data Control


Language (DML) Language (DCL)

 DDL Commands: As the name suggests, allow you to perform task


related to data definition. DDL commands allows you to create a
new table, change the table structure and also we can delete
table from database.
Example: ALTER TABLE, DROP TABLE, CREATE TABLE, CREATE
DATABASE, USE command etc.

 DML Commands: DML commands is a language that enables


users to access or manipulate data as organized by the
appropriate data model. Using DML commands we can retrieve
data, insert data, delete data, update data from the tables of the
database.
Example: SELECT statement, INSERT INTO statement, DELETE etc.
Some MYSQL Elements

By: Ritu Pandey PGT(Computer Science)


SIMPLE QUERIES IN SQL

These basic elements are:


i) Literals: Literals refers to a fixed data value. This data value
may be of character type or numeric type.
Numbers that are not enclosed within quotation are numeric
literals. E.g., 22,56 , 78.5etc. it can store a maximum of 53 digits
of precision.

ii) Data Types:


MySQL uses many different data types, divided into three
categories.
Numeric
(INT, FLOAT)

Dat
Date and Time
a
(DATE, TIME
Typ
Numeric
es
(INT, FLOAT)
)

String/Text
(CHAR, VARCHAR )

INT- A normal-sized integer that can be signed or unsigned. If signed,


the allowable range -2147483648 to 2147483647. If unsigned, the

By: Ritu Pandey PGT(Computer Science)


SIMPLE QUERIES IN SQL

allowable range is from 0 to 4294967295. You can specify a width up to


4 digits.
FLOAT(M,D)- A floating-point number that cannot be unsigned. You
can define the display length(M) and the number of decimals(D) and
will default to 10,2. Decimal precision can go to 24 places for the
FLOAT.
DATE- A date in YYYY-MM-DD format, between 1000-01-01 and
9999-12-13.
DATETIME- YYYY-MM-DD HH:MM:SS format
CHAR(M)- A fixed length string between 1 and 255 characters in
length, right-padded with spaces to the specified length when stored.
Defining a length is not required, by the default is 1.
VARCHAR(M)- A variable length string between 1 and 255 characters
in length. You must define a length when creating a VARCHAR field.

Difference between Char and Varchar Datatypes


CHAR datatype specifies a fixed length character string. When a
column is given datatype as CHAR(n), then MySQL ensures that all
values stored in that column have this length i.e., n bytes. If a value is
shorter than this length n then blanks are added, but the size of value
remains n bytes.
VARCHAR, specifies a variable length string. When a column is given
datatypes as VARCHAR(n), then the maximum size a value in this
column can have is n bytes. Each value that is stored in this column

By: Ritu Pandey PGT(Computer Science)


SIMPLE QUERIES IN SQL

stores exactly as you specify it. i.e., no blanks are added if the length is
shorter than maximum length n, then an error message is displayed.
CHAR VARCHAR
1.CHAR data type provides fixed 1.VARCHAR data type provides
length memory storage. variable length memory storage.
2. The CHAR data type can store a 2.The VARCHAR data type can
maximum of 0 to 255 characters. store a maximum number up to
65,535
3. CHAR data type is used when 3.VARCHAR data types is used
the data entries in a column are when the data entries in a column
expected to be of the same size. are expected to vary considerably
in size.
4.CHAR(n) will take n characters 4.VARCHAR(n) will take only the
of storage even if you enter less required storage for the actual
than n characters to that column. number of characters entered to
that column.
5. If a value entered is shorter 5.No blanks are added if the
than its length x, then blanks are length is shorter than the
added. maximum length, n.
6. CHAR data type takes memory 6.VARCHAR takes up memory
space of 1 byte per character. space of 1 byte per character, +2
bytes to hold variable length
information.
7.Seacrh operation is faster is 7. Search operation works slower
with CHAR data type column. in VARCHAR data type column as
compared to CHAR type
8.Example, name char(10); 8.Example, name varchar(10);
Name=”Amit”; Name=”Amit”;

By: Ritu Pandey PGT(Computer Science)


SIMPLE QUERIES IN SQL

Name field occupies 10 bytes, Name field occupies 4+2=6 bytes,


with the first 4 bytes with values the first four bytes for value and
and the rest with blank data. the other two bytes for variable
length information.

iii) NULL Values: If a column in a row has no value, then column is


said to be null, or to contain a null. Nulls can be appear in
columns of any data type provided, if they are not restricted by
NOT NULL or primary key integrity constraints.
iv) Comments: Example, /* SQL Commands */

By: Ritu Pandey PGT(Computer Science)

You might also like