0% found this document useful (0 votes)
35 views

Mysql

Uploaded by

Splixus07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Mysql

Uploaded by

Splixus07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

mysql> create database cbse2024;

Query OK, 1 row affected (0.01 sec)

mysql> use cbse2024;


Database changed
mysql> create table orders (orrno int, item varchar(7), qty int,
rate int, ordate date);
Query OK, 0 rows affected (0.03 sec)

mysql> insert into orders values(1001, 'rice', 23, 120, '2023-09-


10');
Query OK, 1 row affected (0.01 sec)

mysql> insert into orders values(1002, 'pulses', 13, 120, '2023-10-


18');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO ORDERS VALUES (1003, 'RICE', 25,110, '2023-11-


17') ;
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO ORDERS VALUES (1004, 'WHEAT', 28, 65, ' 2023-12-
25 ') ;
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> INSERT INTO ORDERS VALUES (1005, 'PULSES' ,16,110, '2024-01-


15');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO ORDERS VALUES (1006, 'WHEAT', 27,55, '2024-04-


15');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO ORDERS VALUES (1007, 'WHEAT', 25, 60, 2024-04-
30*);
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ')' at line 1
mysql> INSERT INTO ORDERS VALUES (1007, 'WHEAT', 25, 60, '2024-04-
30');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM ORDERS;


+-------+--------+------+------+------------+
| orrno | item | qty | rate | ordate |
+-------+--------+------+------+------------+
| 1001 | rice | 23 | 120 | 2023-09-10 |
| 1002 | pulses | 13 | 120 | 2023-10-18 |
| 1003 | RICE | 25 | 110 | 2023-11-17 |
| 1004 | WHEAT | 28 | 65 | 2023-12-25 |
| 1005 | PULSES | 16 | 110 | 2024-01-15 |
| 1006 | WHEAT | 27 | 55 | 2024-04-15 |
| 1007 | WHEAT | 25 | 60 | 2024-04-30 |
+-------+--------+------+------+------------+
7 rows in set (0.00 sec)

mysql> SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM;


+--------+----------+
| ITEM | SUM(QTY) |
+--------+----------+
| rice | 48 |
| pulses | 29 |
| WHEAT | 80 |
+--------+----------+
3 rows in set (0.00 sec)

mysql> SELECT ITEM, QTY FROM ORDERS WHERE ORDATE BETWEEN '2023-11-
01' AND '2023-12-31';
+-------+------+
| ITEM | QTY |
+-------+------+
| RICE | 25 |
| WHEAT | 28 |
+-------+------+
2 rows in set (0.00 sec)

mysql> SELECT ORDNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND
RATE >= 60;
ERROR 1054 (42S22): Unknown column 'ORDNO' in 'field list'
mysql> SELECT ORRNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND
RATE >= 60;
+-------+------------+
| ORRNO | ORDATE |
+-------+------------+
| 1004 | 2023-12-25 |
| 1007 | 2024-04-30 |
+-------+------------+
2 rows in set (0.00 sec)

mysql> save
-> save;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'save
save' at line 1
mysql>

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| cbse2024 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.03 sec)

mysql> create table PROJECTS (P_id CHAR(4), Fname VARCHAR(27),


Language VARCHAR(7), Startdate DATE, Enddate DATE);
ERROR 1046 (3D000): No database selected
mysql> CREATE TABLE PROJECTS (P_id CHAR(4), Fname VARCHAR(27),
Language VARCHAR(7), Startdate DATE, Enddate DATE);
ERROR 1046 (3D000): No database selected
mysql> use database cbse2024;
ERROR 1049 (42000): Unknown database 'database'
mysql> use cbse2024;
Database changed
mysql> CREATE TABLE PROJECTS (P_id CHAR(4), Fname VARCHAR(27),
Language VARCHAR(7), Startdate DATE, Enddate DATE);
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO PROJECTS VALUES('POO1', 'School Management


System', 'Python', '2023-01-12','2023-04-03');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO PROJECTS VALUES('P002', 'Hotel Management


System', 'C++', '2022-12-01', '2023-02-02');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO PROJECTS VALUES('P003', 'Blood Bank', 'Python',


'2023-02-11', '2023-03-02');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO PROJECTS VALUES('P004', Payroll Management
System', 'Python', '2023-03-12', '2023-06-02');
'> INSERT INTO PROJECTS VALUES('P004', Payroll Management
System', 'Python', '2023-03-12', '2023-06-02');
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'Management System', 'Python', '2023-03-12',
'2023-06-02');
INSERT INTO PROJECTS ' at line 1
mysql> INSERT INTO PROJECTS VALUES('P004',' Payroll Management
System', 'Python', '2023-03-12', '2023-06-02');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM PROJECTS;


+------+----------------------------+----------+------------
+------------+
| P_id | Fname | Language | Startdate |
Enddate |
+------+----------------------------+----------+------------
+------------+
| POO1 | School Management System | Python | 2023-01-12 | 2023-
04-03 |
| P002 | Hotel Management System | C++ | 2022-12-01 | 2023-
02-02 |
| P003 | Blood Bank | Python | 2023-02-11 | 2023-
03-02 |
| P004 | Payroll Management System | Python | 2023-03-12 | 2023-
06-02 |
+------+----------------------------+----------+------------
+------------+
4 rows in set (0.00 sec)

mysql> DESC PROJECTS


-> DESC PROJECTS;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'DESC PROJECTS' at line 2
mysql> show cbse2024;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'cbse2024' at line 1
mysql> show tables;
+--------------------+
| Tables_in_cbse2024 |
+--------------------+
| orders |
| projects |
+--------------------+
2 rows in set (0.02 sec)

mysql> ALTER TABLE PROJECTS AND PRIMARY KEY(P_id);


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'AND PRIMARY KEY(P_id)' at line 1
mysql> DESC PROJECTS;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| P_id | char(4) | YES | | NULL | |
| Fname | varchar(27) | YES | | NULL | |
| Language | varchar(7) | YES | | NULL | |
| Startdate | date | YES | | NULL | |
| Enddate | date | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> ALTER TABLE PROJECTS AND PRIMARY KEY(P_id);


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'AND PRIMARY KEY(P_id)' at line 1
mysql> ALTER TABLE PROJECTS ADD PRIMARY KEY(P_id);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC PROJECTS;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| P_id | char(4) | NO | PRI | NULL | |
| Fname | varchar(27) | YES | | NULL | |
| Language | varchar(7) | YES | | NULL | |
| Startdate | date | YES | | NULL | |
| Enddate | date | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM PROJECTS:


-> SELECT * FROM PROJECTS;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ':
SELECT * FROM PROJECTS' at line 1
mysql> SELECT * FROM PROJECTS;
+------+----------------------------+----------+------------
+------------+
| P_id | Fname | Language | Startdate |
Enddate |
+------+----------------------------+----------+------------
+------------+
| P002 | Hotel Management System | C++ | 2022-12-01 | 2023-
02-02 |
| P003 | Blood Bank | Python | 2023-02-11 | 2023-
03-02 |
| P004 | Payroll Management System | Python | 2023-03-12 | 2023-
06-02 |
| POO1 | School Management System | Python | 2023-01-12 | 2023-
04-03 |
+------+----------------------------+----------+------------
+------------+
4 rows in set (0.00 sec)

mysql> UPDATE PROJECTS SET Language='Python' WHERE P_id='P002';


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> SELECT * FROM PROJECTS;


+------+----------------------------+----------+------------
+------------+
| P_id | Fname | Language | Startdate |
Enddate |
+------+----------------------------+----------+------------
+------------+
| P002 | Hotel Management System | Python | 2022-12-01 | 2023-
02-02 |
| P003 | Blood Bank | Python | 2023-02-11 | 2023-
03-02 |
| P004 | Payroll Management System | Python | 2023-03-12 | 2023-
06-02 |
| POO1 | School Management System | Python | 2023-01-12 | 2023-
04-03 |
+------+----------------------------+----------+------------
+------------+
4 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| cbse2023compt |
| cbse2024 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.03 sec)

mysql> change cbse2023compt;


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'cbse2023compt' at line 1
mysql> use cbse2023compt;
Database changed
mysql> create table GARMENT( GCODE VARCHAR(4), TYPE CHAR(20), PRICE
INT(3), FCODE VARCHAR(3), ODR_DATE DATE);
Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql> INSERT INTO GARMENT VALUES("G101", "EVENING GOWN", 850,


"F03", '2008-12-19');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO GARMENT VALUES('G102', 'SLACKS', 750, 'F02',


'2020-10-20');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO GARMENT VALUES('G103', 'FROCK', 1000, 'F01',


'2021-09-09');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO GARMENT VALUES('G104', 'TULIP SKIRT', 1550,
'F01', '2021-08-10');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO GARMENT VALUES('G105', 'BABY TOP', 1500, 'F02',


'2020-03-31');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO GARMENT VALUES('G106', 'FORMAL PANT', 1250,


'F01', '2019-01-06');
Query OK, 1 row affected (0.01 sec)

mysql> show garment;


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'garment' at line 1
mysql> desc garment;
+----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+-------+
| GCODE | varchar(4) | YES | | NULL | |
| TYPE | char(20) | YES | | NULL | |
| PRICE | int | YES | | NULL | |
| FCODE | varchar(3) | YES | | NULL | |
| ODR_DATE | date | YES | | NULL | |
+----------+------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> select distinct(count(FCODE)) from garment;


+----------------+
| (count(FCODE)) |
+----------------+
| 6 |
+----------------+
1 row in set (0.00 sec)

mysql> select count(distinct(FCODE)) from garment;


+------------------------+
| count(distinct(FCODE)) |
+------------------------+
| 3 |
+------------------------+
1 row in set (0.01 sec)

mysql> select FCODE, COUNT(*), MIN(PRICE) FROM GARMENT GROUP BY


FCODE HAVING COUNT(*) > 1;
+-------+----------+------------+
| FCODE | COUNT(*) | MIN(PRICE) |
+-------+----------+------------+
| F02 | 2 | 750 |
| F01 | 3 | 1000 |
+-------+----------+------------+
2 rows in set (0.01 sec)

mysql> SELECT * FROM GARMENT WHERE TYPE LIKE 'F%';


+-------+-------------+-------+-------+------------+
| GCODE | TYPE | PRICE | FCODE | ODR_DATE |
+-------+-------------+-------+-------+------------+
| G103 | FROCK | 1000 | F01 | 2021-09-09 |
| G106 | FORMAL PANT | 1250 | F01 | 2019-01-06 |
+-------+-------------+-------+-------+------------+
2 rows in set (0.00 sec)

mysql> show garment;


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'garment' at line 1
mysql> show tables;
+-------------------------+
| Tables_in_cbse2023compt |
+-------------------------+
| garment |
| sport |
| student |
+-------------------------+
3 rows in set (0.01 sec)

You might also like