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

3 Final MySQL Basic Elements

This document provides an overview of MySQL basics including literals, data types, NULL values, comments, constraints, and DDL and DML commands. It defines literals as fixed data values that can be numeric or character text enclosed in single or double quotes. It describes various numeric and character data types supported in MySQL and explains NULL values represent an absence of data. It also defines constraints as rules that determine permissible changes to a database and provides examples of primary key, unique, not null, check, default and foreign key constraints. Finally, it distinguishes DDL commands like CREATE, DROP, ALTER for schema definition from DML commands like INSERT, UPDATE, DELETE, SELECT for data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

3 Final MySQL Basic Elements

This document provides an overview of MySQL basics including literals, data types, NULL values, comments, constraints, and DDL and DML commands. It defines literals as fixed data values that can be numeric or character text enclosed in single or double quotes. It describes various numeric and character data types supported in MySQL and explains NULL values represent an absence of data. It also defines constraints as rules that determine permissible changes to a database and provides examples of primary key, unique, not null, check, default and foreign key constraints. Finally, it distinguishes DDL commands like CREATE, DROP, ALTER for schema definition from DML commands like INSERT, UPDATE, DELETE, SELECT for data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Know Python Bytes

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

 What are constraints?


 Understanding DDL and DML commands
MySQL basic Elements

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

NUMERIC types STRING / TEXT/ DATE & TIME types


CHARACTER types

Int/ Integer/ Number Char Date

Tinyint Varchar
Year
Smallint Varchar2
Time
Mediumint Blob/ Text
Datetime
Bigint TinyBlob
Timestamp
Float MediumBlob
Double LongBlob
Decimal

Data Type: It is the kind of data which a column of a table holds.


DATA TYPES Description Syntax

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

Processing is simpler. Processing is complex.

Name Char(6) Name Varchar(6)

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.

Any arithmetic expression containing a NULL, always evaluates to NULL.


For eg.
ADMNO NAME CITY DOB
MARKS 80+0+NULL+60 =NULL
25 - null = null
80 Null - 25 = Null
40 * NULL = NULL
0 NULL * 5.2 = NULL
NULL / 20 = NULL
NULL 10 / NULL = NULL
0/NULL=NULL
60 NULL/0=NULL
COMMENTS

 Non executable statements which are ignored.


 Statements which are not executed
 It can appear anywhere within the code.
 Given for documentation purpose.

Begin the comment with / *


Begin the comment with --
Begin the comment with #
POINTS TO REMEMBER…
 MySQL is not case sensitive.

 You can write commands(instructions to database) in


either uppercase/lowercase/or in a mixed way of both the
cases.
 For Eg. If the name of a relation(table) is Student then,
Student, STUDENT,sTUDENT,StUdEnT
will represent same relation.

 Underscore is allowed in the naming of a relational


object.
 For eg. Following are some of the valid way of naming a
DB(database) object
Student,Stu_dent,Student1,Student_1
represent different but, valid DB objects
COMMANDS, CLAUSES, KEYWORD,ARGUMENTS
Commands  instructions to database
Eg.
SELECT name FROM student WHERE marks>80;

Clauses One or More logically distinct parts SELECT name


in a command.
Eg. FROM student (From clause)
WHERE marks>80(Where clause) FROM student
Keyword Certain specific words known by
the language processors WHERE marks>80;
Eg. From,where

Arguments Arguments complete or modify


the meaning of a clause
Eg. name
What are Constraints ????
Integrity Constraints:- (or constraints)
These are certain rules that are applicable on a database at all times.
Integrity constraints determine what all changes are permissible to a database.

Types of Integrity Constraint:-


 Primary Key (attribute is set to be the primary key of the table)
 Unique (attributes having unique values
 Not Null (attributes cannot be left blank or NULL)
 Check (attributes are checked for condition)
 Default (attributes are given default values if left blank)
 Foreign Key (references to the primary key of another table)
Understanding DDL and DML queries
DDL Commands (Data Definition Language)
CREATE: Create commands are used to create schema objects eg. tables, indexes.
DROP: Drop commands are used to delete or remove schema objects eg. tables
ALTER: Alter commands are used to modify or change the definition of already existing schema
objects.
DML Commands (Data Manipulation Language)
INSERT: Insertion of information in the table or schema objects
UPDATE : Modification of data stored in the table or database
DELETE: Deletion of information from the table or schema objects
SELECT: Retrieval of information stored in the table or database

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.

You might also like