PRDBMS All Practice Code
PRDBMS All Practice Code
describe fruits;
describe students;
select ascii('7');
select bin('13');
select bit_length('keval');
select char_length('dhorajiya');
select concat('sm','i','t');
select concat_ws('*','smit','gadhiya');
select conv('d',16,2);
select find_in_set('a','p,r,a,c,h,i');
select format(12843.98765,3);
select hex('77');
select insert('keval',2,4,'dhorajiya');
select instr('dhorajiya','ji');
select lower('KEVAL');
select left('dhorajiya',5);
select right('dhorajiya',4);
select length('gadhiya');
select locate('ya','dhorajiya');
select lpad('ke',4,'val');
select rpad('ke',4,'val');
select repeat('smit',3);
select replace('smit','s','fs');
select reverse('gadhiya');
select strcmp('keval','KEVAL');
select substring('typewriter',5);
select substring('typewriter',3,4);
Name VARCHAR(50),
Contact DECIMAL(10)
);
describe suppliers;
Product_ID INT(10),
Code VARCHAR(50),
Name VARCHAR(50),
Quantity INT(10),
Supplier_ID INT(10),
Price DECIMAL(7,2),
);
describe Sproduct;
INSERT INTO Sproduct VALUES (1, 'SP001', 'Product A', 20, 1, 1000.00),
Random_Name VARCHAR(50),
Random_Value INT(5));
describe random_table;
show tables;
OUTPUT:~
+--------+----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------------------------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| price | decimal(5,2) | YES | | NULL | |
| season | set('Winter','Summer','Monsoon') | YES | | NULL | |
+--------+----------------------------------+------+-----+---------+-------+
+------+-------------+--------+---------+
| id | name | price | season |
+------+-------------+--------+---------+
| 1 | Mango | 60.15 | Summer |
| 2 | Guava | 80.72 | Winter |
| 3 | Pomogranate | 100.45 | Monsoon |
+------+-------------+--------+---------+
+--------+--------------------------------------------+------+-----+---------
+-------+
| Field | Type | Null | Key | Default |
Extra |
+--------+--------------------------------------------+------+-----+---------
+-------+
| RollNo | varchar(10) | YES | | NULL |
|
| name | varchar(20) | YES | | NULL |
|
| gender | enum('male','female') | YES | | NULL |
|
| hobby | set('dancing','singing','drawing','music') | YES | | NULL |
|
+--------+--------------------------------------------+------+-----+---------
+-------+
+--------+---------+--------+---------+
| RollNo | name | gender | hobby |
+--------+---------+--------+---------+
| 18 | Anushka | female | music |
| 37 | Krisha | female | drawing |
| 12 | Aryan | male | singing |
+--------+---------+--------+---------+
+--------+---------+
| name | hobby |
+--------+---------+
| Krisha | drawing |
+--------+---------+
+--------+---------+--------+---------+
| RollNo | name | gender | hobby |
+--------+---------+--------+---------+
| 18 | Anushka | female | dancing |
| 37 | Krisha | female | drawing |
| 12 | Aryan | male | singing |
+--------+---------+--------+---------+
+------+-------------+--------+---------+
| id | name | price | season |
+------+-------------+--------+---------+
| 1 | Mango | 60.15 | Summer |
| 3 | Pomogranate | 100.45 | Monsoon |
+------+-------------+--------+---------+
+--------+---------+
| RollNo | name |
+--------+---------+
| 18 | Anushka |
| 12 | Aryan |
+--------+---------+
+------------+
| ascii('7') |
+------------+
| 55 |
+------------+
+-----------+
| bin('13') |
+-----------+
| 1101 |
+-----------+
+---------------------+
| bit_length('keval') |
+---------------------+
| 40 |
+---------------------+
+--------------------------+
| char_length('dhorajiya') |
+--------------------------+
| 9 |
+--------------------------+
+----------------------+
| concat('sm','i','t') |
+----------------------+
| smit |
+----------------------+
+---------------------------------+
| concat_ws('*','smit','gadhiya') |
+---------------------------------+
| smit*gadhiya |
+---------------------------------+
+----------------+
| conv('d',16,2) |
+----------------+
| 1101 |
+----------------+
+--------------------------------+
| find_in_set('a','p,r,a,c,h,i') |
+--------------------------------+
| 3 |
+--------------------------------+
+-----------------------+
| format(12843.98765,3) |
+-----------------------+
| 12,843.988 |
+-----------------------+
+-----------+
| hex('77') |
+-----------+
| 3737 |
+-----------+
+---------------------------------+
| insert('keval',2,4,'dhorajiya') |
+---------------------------------+
| kdhorajiya |
+---------------------------------+
+-------------------------+
| instr('dhorajiya','ji') |
+-------------------------+
| 6 |
+-------------------------+
+----------------+
| lower('KEVAL') |
+----------------+
| keval |
+----------------+
+---------------------+
| left('dhorajiya',5) |
+---------------------+
| dhora |
+---------------------+
+----------------------+
| right('dhorajiya',4) |
+----------------------+
| jiya |
+----------------------+
+-------------------+
| length('gadhiya') |
+-------------------+
| 7 |
+-------------------+
+--------------------------+
| locate('ya','dhorajiya') |
+--------------------------+
| 8 |
+--------------------------+
+--------------------+
| lpad('ke',4,'val') |
+--------------------+
| vake |
+--------------------+
+--------------------+
| rpad('ke',4,'val') |
+--------------------+
| keva |
+--------------------+
+-----------------+
| ltrim(' smit') |
+-----------------+
| smit |
+-----------------+
+------------------+
| rtrim('smit ') |
+------------------+
| smit |
+------------------+
+---------+
| oct(13) |
+---------+
| 15 |
+---------+
+------------------+
| repeat('smit',3) |
+------------------+
| smitsmitsmit |
+------------------+
+--------------------------+
| replace('smit','s','fs') |
+--------------------------+
| fsmit |
+--------------------------+
+--------------------+
| reverse('gadhiya') |
+--------------------+
| ayihdag |
+--------------------+
+-------------------------+
| strcmp('keval','KEVAL') |
+-------------------------+
| 0 |
+-------------------------+
+---------------------------+
| substring('typewriter',5) |
+---------------------------+
| writer |
+---------------------------+
+--------------------------------+
| substring('typewriter' from 6) |
+--------------------------------+
| riter |
+--------------------------------+
+-----------------------------+
| substring('typewriter',3,4) |
+-----------------------------+
| pewr |
+-----------------------------+
+--------+--------+--------+---------+
| RollNo | name | gender | hobby |
+--------+--------+--------+---------+
| 37 | Krisha | female | drawing |
| 12 | Aryan | male | singing |
+--------+--------+--------+---------+
+--------+---------+--------+---------+
| RollNo | name | gender | hobby |
+--------+---------+--------+---------+
| 18 | Anushka | female | dancing |
+--------+---------+--------+---------+
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Supplier_ID | int | NO | PRI | NULL | |
| Name | varchar(50) | YES | | NULL | |
| Contact | decimal(10,0) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| Product_ID | int | YES | | NULL | |
| Code | varchar(50) | YES | | NULL | |
| Name | varchar(50) | YES | | NULL | |
| Quantity | int | YES | | NULL | |
| Supplier_ID | int | YES | MUL | NULL | |
| Price | decimal(7,2) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
+-------------+------------+----------+
| Supplier_ID | Name | Contact |
+-------------+------------+----------+
| 1 | Supplier A | 75321489 |
| 2 | Supplier B | 98765210 |
| 3 | Supplier C | 45689120 |
| 4 | Supplier D | 78912560 |
| 5 | Supplier E | 31654970 |
+-------------+------------+----------+
+------------+-------+-----------+----------+-------------+---------+
| Product_ID | Code | Name | Quantity | Supplier_ID | Price |
+------------+-------+-----------+----------+-------------+---------+
| 1 | SP001 | Product A | 20 | 1 | 1000.00 |
| 2 | SP002 | Product B | 15 | 2 | 1500.00 |
| 3 | SP003 | Product C | 25 | 3 | 2000.00 |
| 4 | SP004 | Product D | 10 | 4 | 2500.00 |
| 5 | SP005 | Product E | 5 | 5 | 3000.00 |
+------------+-------+-----------+----------+-------------+---------+
+------------+-------+-----------+----------+-------------+---------+
| Product_ID | Code | Name | Quantity | Supplier_ID | Price |
+------------+-------+-----------+----------+-------------+---------+
| 1 | SP001 | Product A | 20 | 1 | 1000.00 |
| 2 | SP002 | Product B | 15 | 2 | 1500.00 |
| 4 | SP004 | Product D | 10 | 4 | 2500.00 |
+------------+-------+-----------+----------+-------------+---------+
+----+-------------+--------------+
| ID | Random_Name | Random_Value |
+----+-------------+--------------+
| 5 | Alpha | 100 |
| 6 | Beta | 200 |
| 7 | Gamma | 300 |
| 8 | Delta | 400 |
| 9 | Epsilon | 500 |
+----+-------------+--------------+
+----+-------------+--------------+
| ID | Random_Name | Random_Value |
+----+-------------+--------------+
| 7 | Gamma | 300 |
| 8 | Delta | 400 |
| 9 | Epsilon | 500 |
+----+-------------+--------------+
+---------+
| Name |
+---------+
| Alpha |
| Beta |
| Gamma |
| Delta |
| Epsilon |
+---------+
+---------+
| maximum |
+---------+
| 3000.00 |
+---------+
+------------+------------+-------------+--------------+------------+
| max(price) | min(price) | avg(price) | count(price) | sum(price) |
+------------+------------+-------------+--------------+------------+
| 3000.00 | 1000.00 | 2000.000000 | 5 | 10000.00 |
+------------+------------+-------------+--------------+------------+
+------------+-------+-----------+----------+-------------+---------+
| Product_ID | Code | Name | Quantity | Supplier_ID | Price |
+------------+-------+-----------+----------+-------------+---------+
| 5 | SP005 | Product E | 5 | 5 | 3000.00 |
| 4 | SP004 | Product D | 10 | 4 | 2500.00 |
| 2 | SP002 | Product B | 15 | 2 | 1500.00 |
| 1 | SP001 | Product A | 20 | 1 | 1000.00 |
| 3 | SP003 | Product C | 25 | 3 | 2000.00 |
+------------+-------+-----------+----------+-------------+---------+
+------------+-------+-----------+----------+-------------+---------+
| Product_ID | Code | Name | Quantity | Supplier_ID | Price |
+------------+-------+-----------+----------+-------------+---------+
| 3 | SP003 | Product C | 25 | 3 | 2000.00 |
| 1 | SP001 | Product A | 20 | 1 | 1000.00 |
| 2 | SP002 | Product B | 15 | 2 | 1500.00 |
| 4 | SP004 | Product D | 10 | 4 | 2500.00 |
| 5 | SP005 | Product E | 5 | 5 | 3000.00 |
+------------+-------+-----------+----------+-------------+---------+
+----------+
| count(*) |
+----------+
| 2 |
+----------+
+-------+--------+
| Count | gender |
+-------+--------+
| 2 | female |
| 1 | male |
+-------+--------+
+--------+
| gender |
+--------+
| female |
| male |
+--------+
+----+-------------+
| ID | Random_Name |
+----+-------------+
| 5 | Alpha |
| 6 | Beta |
| 7 | Gamma |
| 8 | Delta |
| 9 | Epsilon |
+----+-------------+
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| ID | int | NO | PRI | NULL | |
| Random_Name | varchar(50) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
+----+-------------+----------+
| ID | Random_Name | mfg_year |
+----+-------------+----------+
| 5 | Alpha | NULL |
| 6 | Beta | NULL |
| 7 | Gamma | NULL |
| 8 | Delta | NULL |
| 9 | Epsilon | NULL |
+----+-------------+----------+
+----------------------------------+
| Tables_in_sandbox_db |
+----------------------------------+
| fruits |
| random |
| sproduct |
| students |
| suppliers |
+----------------------------------+