Database Lab
Database Lab
Database Lab
Lab task 1:The working of reverse, replace, trim, position and ascii function.
Code:
select reverse(stu_name) as reverse from student;
select replace("I am a bad boy","bad","good");
select ltrim(" jakir ");
select rtrim(" jakir ");
select position("is" in "my name is jakir") as name;
select ascii("%");
select ascii("#");
output:
6
Discussion:
Reverse: in MySQL, the REVERSE function is used to reverse the order of characters in a
string. Here reverse student name from student table
ASCII:The ASCII function in MySQL returns the ASCII value (integer representation) of the
leftmost character of a given string
Ltream: The LTRIM function in MySQL is used to remove leading spaces (or other specified
characters) from the left side of a string. This is often used for cleaning up data where
leading spaces may cause issues.
Rtream: The RTRIM function in MySQL is used to remove trailing spaces (or other specified
characters) from the right side of a string. This is useful for cleaning up data where trailing
spaces may cause problems
Position: The POSITION function (or LOCATE function, they are synonymous in MySQL) is
used to find the position of a substring within a string. It returns the starting position of the
first occurrence of a substring in the string
Discussion: here the email address column is added after creating this table.
7
Lab task 3: : Create two table and merge them
Code:
Create table table2( t_id int
primary key, t_name
varchar(25), t_contact
varchar(25), t_age int
);
INSERT INTO table2(t_id,t_name,t_contact,t_age)
VALUES
(111, 'shihab' ,1234567,20),
(112, 'mamun',7356783,42 ),
(882, 'Tom' ,458756788,41),
(424, 'Martin',1279876529,30);
output:
8
Discussion: here table 1 t_id use as a foreign key for table 2 table id. After joining tow table
the new table column is t_id, id, t_age.