Preview:
show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> create database varshitha;
Query OK, 1 row affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| varshitha          |
+--------------------+
5 rows in set (0.00 sec)

mysql> use varshitha;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_varshitha |
+---------------------+
| students            |
+---------------------+
1 row in set (0.02 sec)

mysql> desc students;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(50) | NO   |     | NULL    |                |
| age   | int(11)     | YES  |     | NULL    |                |
| grade | varchar(10) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

mysql> select * from students;
+----+-------+------+-------+
| id | name  | age  | grade |
+----+-------+------+-------+
|  1 | Alice |   20 | A     |
|  2 | Bob   |   22 | B     |
+----+-------+------+-------+
2 rows in set (0.00 sec)

mysql> DELIMITER //
mysql> CREATE PROCEDURE selectGradeAStudents()
    -> BEGIN
    ->     SELECT * FROM Students WHERE grade = 'A';
    -> END //
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
mysql>
mysql> DELIMITER //
mysql> CREATE FUNCTION getAverageAgeByGrade(gradeInput VARCHAR(10))
    -> RETURNS DOUBLE
    -> BEGIN
    ->     DECLARE avgAge DOUBLE;
    ->     SELECT AVG(age) INTO avgAge FROM Students WHERE grade = gradeInput;
    ->     RETURN avgAge;
    -> END //
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter