Mysql 2
Mysql 2
COMMANDS
CREATING TABLE
• CREATE TABLE:- Used to create table in Mysql
• CREATE TABLE <tablename>
(<columnname1> <datatype> (<size>),
<columnname2> <datatype> (<size>),
……..
);
Create Table
• Eg:-
• CREATE TABLE Student
(rollno int(4),
name varchar(15),
marks decimal(5,2));
INSERTING RECORDS IN TABLE
• INSERT INTO:- Used to insert record in a table.
• INSERT INTO <tablename> VALUES (value1,value2,
…..);
• INSERT INTO <tablename>
(<columnname1>,<columnname2>) VALUES
(<value1>,<value2>);
• Eg:-
• INSERT INTO student VALUES (1,”ABC”,85.5);
• INSERT INTO student (rollno,marks) VALUES (2,90);
Queries in mysql
• SELECT statement:- Used to make queries in
mysql. SELECT * from student;
• DISTINCT:- Used to eliminate duplicate data in
query. SELECT DISTINCT name from student;
• DESCRIBE:- Used to view the structure of
table. DESCRIBE student;
• Column Alias:- “AS”
SELECT rollno as “rollnumber” from student;
CONDITIONS
• WHERE clause:- used to specify condition with
select statement
• Condition based on a range:-
BETWEEN:- Used for making ranges checks in
queries
• Condition based on list:-
IN:- Used for selecting values from a list of values
• Conditions based on pattern matching:-
LIKE:-Used for making character comparison using
percentage(%) and underscore(_)
FUNCTIONS
• A function is a special type of predefined
command set that performs some operations
and return a single value.
Eg pow(2,3) 8
• Single Row Functions
• Multiple Row Functions
Single Row Functions
• String Functions:- Lcase(), Ucase(), Concat(),
Instr(), Length(), Rtrim(), Ltrim(), Substr()
• Numeric Functions:- Round(), Truncate(),
Pow(), Mod()
• Date Functions:-Date(), Now(), Year() etc.
Aggregate Functions
• AVG():- Returns the average value of numeric column.
• COUNT():- Returns the number of rows that match the
criteria in where clause
• MAX():- Returns the largest value of the selected
column
• MIN():- Returns the smallest value of the selected
column
• SUM():- Returns the total sum of a numeric column
• COUNT(*):- Returns total number of records from table
Assignment
• Q.1 What is SQL? What are different categories of commands available
in SQL?
• Q.2 Differentiate between CHAR and VARCHAR datatypes.
• Q.3 Differentiate between DDL and DML commands.
• Q.4 Write two examples of DBMS software.
• Q.5What is meant by NULL value in Mysql?
• Q.6A table Club has 4 rows and 3 columns. What is the degree and
cardinality of the table if 2 more records are added to it?
• Q.7 What do you mean by table level constraints and column level
constraints? Explain with example.
• Q.8 What is a data type? Name some data types available in Mysql.
• How would you calculate 13*15 in mysql?
• Write mysql command to display the list of existing database.