DML Command and Various Clauses
DML Command and Various Clauses
VARCHAR(M) Variable length string between 1 and 255. it takes size as per the data
entered for example with VARCHAR(20) if the data entered in MOBILE
then it will take only 6 byte. It is useful for the data like name, address
where the number of character to be enter is not fixed.
Difference between CHAR & VARCHAR
CHAR VARCHAR
Fixed length string Variable length string
Used where number of character to enter Used where number of character to be
is fixed like Grade, EmpCode, etc enter is not fixed like name, address etc.
Fast, no memory allocation every time Slow, as it take size according to data so
every time memory allocation is done
It takes more memory It takes less space
NULL VALUE
• NULL means missing information
• NULL can appear in any type of column if it is
not restricted by NOT NULL or PRIMARY KEY
• Always remember NULL is neither equal to 0
nor space. NULL means nothing
• Used in situation like if email id is not available
with students then we will insert NULL
COMMENTS
• It is a text that is not executed, only for
documentation purpose. Comments in MySQL
can be written as
– Begin the comment with /* and */
– Begin the comment with – (followed by space)
– Begin then comment with #
• For example
– /* Select * from emp where empno=4 */
– Select * from emp; -- it will fetch all details
CREATING and USING DATABASE
CREATE DATABASE <DATABASE NAME>
CREATE DATABASE MYDB;
Note:-
1) char, varchar and date value must be in
single quotes
2) Values must be passed in the order of their column
3) Date values are passed in the format
dd-mon-yyyy i.e. 20-Sep-2015 (in
oracle) yyyy-mm-dd (in mysql)
INSERTING RECORDS IN TABLE
Syntax:-
Syntax:-
Select * / columnnames FROM
tablename [ where condition ]
SELECTING RECORD
Selecting all record and all columns
Select * from emp;
From the above table we can observe that salary of Shaban is NULL i.e.
not assigned, Now if we want 0 or “not assigned” for the salary
information of shaban, we have to use IFNULL()
Select empno,name,IFNULL(Salary,”not assigned”) from emp;