3 Final MySQL Basic Elements
3 Final MySQL Basic Elements
www.knowpythonbytes.blogspot.in
Mrs. Payal Bhattacharjee, PGT(C.Sc.)
K V No.1 Kanchrapara
KVS-RO(Kolkata)
CONTENTS
(LEARNING OUTCOMES)
MySQL basic elements
Literals
Data Types
NULL values
Comments
Points to Remember
Commands,Clauses, Keywords,Arguments
LITERALS
DATA TYPES
NULLS
COMMENTS
LITERALS
• Literals refers to a fixed data value.
• Fixed data value may be of character type or numeric literal.
Eg. , ‘Ajay’, “Thomas”, ‘596’ are all character text literals.
• Character literals can be given in either single quote or double quote.
‘ ’ “ ”
• Numbers that are not enclosed in quotation marks are numeric literals
Eg. 5, 350, 84
CONCEPT OF DATA TYPES
DATA TYPES in MySQL
Tinyint Varchar
Year
Smallint Varchar2
Time
Mediumint Blob/ Text
Datetime
Bigint TinyBlob
Timestamp
Float MediumBlob
Double LongBlob
Decimal
NUMERIC
Number(size) / Used to store a numeric value in a field/column. Number(4)
Integer(size)/ It may be decimal, integer or a real value.
Int(size)
An exact fixed-point number. Decimal(5,2)
Decimal (Size,d) The total number of digits is specified in size.
The number of digits after the decimal point is specified in the d parameter.
The maximum number for size is 65.
The maximum number for d is 30.
The default value for size is 10. The default value for d is 0.
CHARACTER
A FIXED length string (can contain letters, numbers, special characters). Char(10)
Char (size) The size parameter specifies the column length in characters - can be from 0 to 255. Default
is 1
Wastage of extra spaces
Processing is simpler
Varchar (size) / A VARIABLE length string (can contain letters,numbers,special characters) Varchar(10)
Varchar2 (size) The size parameter specifies the maximum column length in characters - can be from 0 to Varchar2(10)
65535
NO wastage of extra space
Processing is complex
DATE
Date A date. Format:YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31' Date
CHAR(size) VARCHAR (size) / VARCHAR2 (size)
A FIXED length string (can contain letters, A VARIABLE length string (can contain letters,
numbers, and special characters). numbers, and special characters).
The size parameter specifies the column length in The size parameter specifies the maximum column
characters - can be from 0 to 255. Default is 1 length in characters - can be from 0 to 65535
Wastage of extra spaces as all data elements may not NO wastage of extra space
use all the space reserved
A V I K A V I K
VARCHAR VARCHAR2
It can store upto 2000bytes of characters It can store upto 4000 bytes of characters
It occupies space for NULL values. It will not occupy any space for NULL values
NULLS
If a column in a record has no value, then column is said to be NULL or to contain a NULL.
A reserved word and a special marker to indicate that a data value doesnot exist in the database.
NULLs can appear in fields of any data type , provided they are not restricted by NOT NULL or
PRIMARY KEY constraint.
NOTE:
Zero and NULL(null) are not equivalent.
EMP
Empno Ename Job Sal Hiredate Deptno
1001 ABC Clerk 20000 25-10-2006 20
1002 EFG Salesman 25000 12-08-2008 10
1006 XYZ Manager 30000 19-05-2008 30
1003 PQR Analyst 30000 10-07-2007 20
Stay safe. Stay aware. Stay healthy. Stay alert.