0% found this document useful (0 votes)
2 views21 pages

Sol Notes

The document contains a series of MySQL commands and their outputs, demonstrating various SQL operations such as selecting data from a table, string manipulation, date functions, and error handling. It showcases the use of functions like CONCAT, LENGTH, and DATE_FORMAT, along with syntax errors encountered during execution. The document also includes examples of querying employee data from a database and manipulating string and date formats.

Uploaded by

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

Sol Notes

The document contains a series of MySQL commands and their outputs, demonstrating various SQL operations such as selecting data from a table, string manipulation, date functions, and error handling. It showcases the use of functions like CONCAT, LENGTH, and DATE_FORMAT, along with syntax errors encountered during execution. The document also includes examples of querying employee data from a database and manipulating string and date formats.

Uploaded by

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

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 12
Server version: 8.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use 11to12;


Database changed
mysql> desc table emp;
+----+-------------+-------+------------+------+---------------+------+---------
+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len |
ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------
+------+------+----------+-------+
| 1 | SIMPLE | emp | NULL | ALL | NULL | NULL | NULL |
NULL | 8 | 100.00 | NULL |
+----+-------------+-------+------------+------+---------------+------+---------
+------+------+----------+-------+
1 row in set, 1 warning (0.12 sec)

mysql> show * from emp;


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 '* from
emp' at line 1
mysql> select * from emp;
+-----+--------+------+-------+---------+
| eid | ename | exp | esal | edept |
+-----+--------+------+-------+---------+
| 90 | naveen | 0 | NULL | account |
| 100 | chinu | 5 | 20000 | coding |
| 101 | bhoul | 5 | 15000 | coding |
| 102 | millu | 5 | 15000 | coding |
| 104 | raghu | 5 | 10000 | coding |
| 112 | varun | 8 | 30000 | hr |
| 113 | babu | 8 | 50000 | gh |
| 114 | sabhu | 6 | 40000 | ph |
+-----+--------+------+-------+---------+
8 rows in set (0.06 sec)

mysql> select lower (ABCD);


ERROR 1054 (42S22): Unknown column 'ABCD' in 'field list'
mysql> select UPPER (weff);
ERROR 1054 (42S22): Unknown column 'weff' in 'field list'
mysql> select upper (weff);
ERROR 1054 (42S22): Unknown column 'weff' in 'field list'
mysql> select upper(werd);
ERROR 1054 (42S22): Unknown column 'werd' in 'field list'
mysql> select upper('werd');
+---------------+
| upper('werd') |
+---------------+
| WERD |
+---------------+
1 row in set (0.00 sec)

mysql> select lower('ABDUEBS');


+------------------+
| lower('ABDUEBS') |
+------------------+
| abduebs |
+------------------+
1 row in set (0.04 sec)

mysql> select upper(ename) from emp;


+--------------+
| upper(ename) |
+--------------+
| NAVEEN |
| CHINU |
| BHOUL |
| MILLU |
| RAGHU |
| VARUN |
| BABU |
| SABHU |
+--------------+
8 rows in set (0.00 sec)

mysql> select upper(edept) from emp;


+--------------+
| upper(edept) |
+--------------+
| ACCOUNT |
| CODING |
| CODING |
| CODING |
| CODING |
| HR |
| GH |
| PH |
+--------------+
8 rows in set (0.00 sec)

mysql> select left("aaj ridier aa rhaay hai",4);


+-----------------------------------+
| left("aaj ridier aa rhaay hai",4) |
+-----------------------------------+
| aaj |
+-----------------------------------+
1 row in set (0.05 sec)

mysql> select right("aaj ridier aa rhaay hai",4);


+------------------------------------+
| right("aaj ridier aa rhaay hai",4) |
+------------------------------------+
| hai |
+------------------------------------+
1 row in set (0.00 sec)

mysql> select mid("aaj ridier aa rhaay hai"3,4);


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 '3,4)' at
line 1
mysql> select mid("aaj ridier aa rhaay hai",3,4);
+------------------------------------+
| mid("aaj ridier aa rhaay hai",3,4) |
+------------------------------------+
| j ri |
+------------------------------------+
1 row in set (0.00 sec)

mysql> select con('naveen' singh'):


'> select con('naveen' singh');
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 con('naveen' singh')' at line 1
mysql> select con('naveen, singh');
ERROR 1305 (42000): FUNCTION 11to12.con does not exist
mysql> select con('naveen','singh');
ERROR 1305 (42000): FUNCTION 11to12.con does not exist
mysql> select concate('naveen','singh');
ERROR 1305 (42000): FUNCTION 11to12.concate does not exist
mysql> select concate(11,12);
ERROR 1305 (42000): FUNCTION 11to12.concate does not exist
mysql> select concat(11,12);
+---------------+
| concat(11,12) |
+---------------+
| 1112 |
+---------------+
1 row in set (0.34 sec)

mysql> select concat("hanu","man");


+----------------------+
| concat("hanu","man") |
+----------------------+
| hanuman |
+----------------------+
1 row in set (0.00 sec)

mysql> select concat("eid","ename") from emp;


+-----------------------+
| concat("eid","ename") |
+-----------------------+
| eidename |
| eidename |
| eidename |
| eidename |
| eidename |
| eidename |
| eidename |
| eidename |
+-----------------------+
8 rows in set (0.00 sec)

mysql> select concat(eid,"_",ename")from emp;


"> ^C
mysql> select concat(eid,"_",ename)from emp;
+-----------------------+
| concat(eid,"_",ename) |
+-----------------------+
| 90_naveen |
| 100_chinu |
| 101_bhoul |
| 102_millu |
| 104_raghu |
| 112_varun |
| 113_babu |
| 114_sabhu |
+-----------------------+
8 rows in set (0.00 sec)

mysql> select concat(eid,"_",ename) as eid_ename from emp;


+-----------+
| eid_ename |
+-----------+
| 90_naveen |
| 100_chinu |
| 101_bhoul |
| 102_millu |
| 104_raghu |
| 112_varun |
| 113_babu |
| 114_sabhu |
+-----------+
8 rows in set (0.00 sec)

mysql> select char_lenght('gerfehferhht');


ERROR 1305 (42000): FUNCTION 11to12.char_lenght does not exist
mysql> select char_lenght("gerfehferhht");
ERROR 1305 (42000): FUNCTION 11to12.char_lenght does not exist
mysql> select char_length('gerfehferhht');
+-----------------------------+
| char_length('gerfehferhht') |
+-----------------------------+
| 12 |
+-----------------------------+
1 row in set (0.35 sec)

mysql> select char_length('ggggggggg gggg g g g g g g g');


+----------------------------------------------+
| char_length('ggggggggg gggg g g g g g g g') |
+----------------------------------------------+
| 29 |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql> select concat(lenght(eid));


ERROR 1305 (42000): FUNCTION 11to12.lenght does not exist
mysql> select concat(length(eid));
ERROR 1054 (42S22): Unknown column 'eid' in 'field list'
mysql> select concat(length(eid,ename))from emp;
ERROR 1582 (42000): Incorrect parameter count in the call to native function
'length'
mysql> select concat(length(eid,ename)) from emp;
ERROR 1582 (42000): Incorrect parameter count in the call to native function
'length'
mysql> select concat(length(eid,ename));
ERROR 1582 (42000): Incorrect parameter count in the call to native function
'length'
mysql> select concat(length(ename));
ERROR 1054 (42S22): Unknown column 'ename' in 'field list'
mysql> select lenght(concat(eid,"_",ename)) from emp;
ERROR 1305 (42000): FUNCTION 11to12.lenght does not exist
mysql> select length (concat(eid,"_",ename)) from emp;
+--------------------------------+
| length (concat(eid,"_",ename)) |
+--------------------------------+
| 9 |
| 9 |
| 9 |
| 9 |
| 9 |
| 9 |
| 8 |
| 9 |
+--------------------------------+
8 rows in set (0.00 sec)

mysql> select length (concat(eid,"_",ename)) from emp;


+--------------------------------+
| length (concat(eid,"_",ename)) |
+--------------------------------+
| 9 |
| 9 |
| 9 |
| 9 |
| 9 |
| 9 |
| 8 |
| 9 |
+--------------------------------+
8 rows in set (0.00 sec)

mysql> select curdate();


+------------+
| curdate() |
+------------+
| 2024-05-21 |
+------------+
1 row in set (0.04 sec)

mysql> select curdate(dd,mm,yyy);


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
'dd,mm,yyy)' at line 1
mysql> select curdate('dd,mm,yyy");
'>
'> C^C
mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 11:33:21 |
+-----------+
1 row in set (0.00 sec)
mysql> select concat(curdate(),curtime());
+-----------------------------+
| concat(curdate(),curtime()) |
+-----------------------------+
| 2024-05-2111:34:22 |
+-----------------------------+
1 row in set (0.04 sec)

mysql> select concat(curdate()," ",curtime());


+---------------------------------+
| concat(curdate()," ",curtime()) |
+---------------------------------+
| 2024-05-21 11:34:45 |
+---------------------------------+
1 row in set (0.00 sec)

mysql> select now();


+---------------------+
| now() |
+---------------------+
| 2024-05-21 11:34:57 |
+---------------------+
1 row in set (0.00 sec)

mysql> select year(2024,02,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 ',02,30)'
at line 1
mysql> select year(now());
+-------------+
| year(now()) |
+-------------+
| 2024 |
+-------------+
1 row in set (0.04 sec)

mysql> select month(now());


+--------------+
| month(now()) |
+--------------+
| 5 |
+--------------+
1 row in set (0.00 sec)

mysql> select day(now());


+------------+
| day(now()) |
+------------+
| 21 |
+------------+
1 row in set (0.34 sec)

mysql> select hour(now());


+-------------+
| hour(now()) |
+-------------+
| 11 |
+-------------+
1 row in set (0.00 sec)

mysql> select second(now());


+---------------+
| second(now()) |
+---------------+
| 6 |
+---------------+
1 row in set (0.00 sec)

mysql> select year("2024-02-30")


-> ;
+--------------------+
| year("2024-02-30") |
+--------------------+
| NULL |
+--------------------+
1 row in set, 1 warning (0.05 sec)

mysql> select year("2024-02-30");


+--------------------+
| year("2024-02-30") |
+--------------------+
| NULL |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select year("2024-10-20");


+--------------------+
| year("2024-10-20") |
+--------------------+
| 2024 |
+--------------------+
1 row in set (0.00 sec)

mysql> select year("2024-04-31");


+--------------------+
| year("2024-04-31") |
+--------------------+
| NULL |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql>
mysql>
mysql>
mysql>
mysql> select monthname("2024-04-31");
+-------------------------+
| monthname("2024-04-31") |
+-------------------------+
| NULL |
+-------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select date_formate("2012-08-12","%y");


ERROR 1305 (42000): FUNCTION 11to12.date_formate does not exist
mysql> select date_format("2012-08-12","%y");
+--------------------------------+
| date_format("2012-08-12","%y") |
+--------------------------------+
| 12 |
+--------------------------------+
1 row in set (0.33 sec)

mysql> select date_format("2012-08-12","%m");


+--------------------------------+
| date_format("2012-08-12","%m") |
+--------------------------------+
| 08 |
+--------------------------------+
1 row in set (0.00 sec)

mysql> select date_format("2012-08-12","%M");


+--------------------------------+
| date_format("2012-08-12","%M") |
+--------------------------------+
| August |
+--------------------------------+
1 row in set (0.04 sec)

mysql> select date_format(now(),"%t");


+-------------------------+
| date_format(now(),"%t") |
+-------------------------+
| t |
+-------------------------+
1 row in set (0.00 sec)

mysql> select date_format(now(),"%T");


+-------------------------+
| date_format(now(),"%T") |
+-------------------------+
| 11:53:18 |
+-------------------------+
1 row in set (0.00 sec)

mysql> select date_format(now(),"%r");


+-------------------------+
| date_format(now(),"%r") |
+-------------------------+
| 11:54:05 AM |
+-------------------------+
1 row in set (0.00 sec)

mysql> select date_format(now(),"%p");


+-------------------------+
| date_format(now(),"%p") |
+-------------------------+
| AM |
+-------------------------+
1 row in set (0.00 sec)

mysql> select date_format(now(),"%w");


+-------------------------+
| date_format(now(),"%w") |
+-------------------------+
| 2 |
+-------------------------+
1 row in set (0.00 sec)

mysql> select datediff("2005-08-15","2024-05-21");


+-------------------------------------+
| datediff("2005-08-15","2024-05-21") |
+-------------------------------------+
| -6854 |
+-------------------------------------+
1 row in set (0.05 sec)

mysql> select date_format(curdate(),"%d" %

Enter password: ****


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| naveen |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql> create database 11to12;


Query OK, 1 row affected (0.13 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| 11to12 |
| information_schema |
| mysql |
| naveen |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)

mysql> use 11to12


Database changed
mysql> creat table emp(eid int,ename varchar(10),esal float);
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 'creat
table emp(eid int,ename varchar(10),esal float)' at line 1
mysql> create table emp(eid int,ename varchar(10),esal float);
Query OK, 0 rows affected (0.76 sec)

mysql> desc emp;


+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| eid | int | YES | | NULL | |
| ename | varchar(10) | YES | | NULL | |
| esal | float | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

-----------------------------------------------------------------------------------
----------------------------------------------------

-----------------------------Day 2nd
-----------------------------------------------------------------------------------
----------------------------
-----------------------------------------------------------------------------------
--------------------------------------------------------
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| 11to12 |
| information_schema |
| mysql |
| naveen |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)

mysql> create database emp;


Query OK, 1 row affected (0.45 sec)

mysql> create database ducat


-> ;
Query OK, 1 row affected (0.10 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| 11to12 |
| ducat |
| emp |
| information_schema |
| mysql |
| naveen |
| performance_schema |
| sys |
+--------------------+
8 rows in set (0.00 sec)

mysql> use emp


Database changed
mysql> drop dtabase emp;
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 'dtabase
emp' at line 1
mysql> drop database emp;
Query OK, 0 rows affected (0.13 sec)

mysql> use 11to12;


Database changed
mysql> create table emp(eid int,ename varchar(10),esal float);
ERROR 1050 (42S01): Table 'emp' already exists
mysql> show table;
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> show tables;
+------------------+
| Tables_in_11to12 |
+------------------+
| emp |
+------------------+
1 row in set (0.00 sec)

mysql> des emp


-> ;
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 'des emp'
at line 1
mysql> desc emp;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| eid | int | YES | | NULL | |
| ename | varchar(10) | YES | | NULL | |
| esal | float | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> use emp;


ERROR 1049 (42000): Unknown database 'emp'
mysql> use 11to12;
Database changed
mysql> show tables;
+------------------+
| Tables_in_11to12 |
+------------------+
| emp |
+------------------+
1 row in set (0.00 sec)

mysql> insert into emp values(100,'raju',30000);


Query OK, 1 row affected (0.13 sec)

mysql> insert into emp values(104,'raju',30000),(102,'nabbu',20000),


(103,'mohan',15000);
Query OK, 3 rows affected (0.15 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select eid,ename from emp;


+------+-------+
| eid | ename |
+------+-------+
| 100 | raju |
| 104 | raju |
| 102 | nabbu |
| 103 | mohan |
+------+-------+
4 rows in set (0.00 sec)

mysql> select * from emp;


+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
+------+-------+-------+
4 rows in set (0.00 sec)

mysql> insert into emp(ename,esal)values('sonu',20000);


Query OK, 1 row affected (0.42 sec)

mysql> select * emp


-> ;
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 'emp' at
line 1
mysql> select * from emp;
+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
| NULL | sonu | 20000 |
+------+-------+-------+
5 rows in set (0.00 sec)

mysql> insert table (ename,esal)


->
-> values(prabhau,12000);
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 'table
(ename,esal)

values(prabhau,12000)' at line 1
mysql> insert into emp(ename,esal)values('mohan',20000);
Query OK, 1 row affected (0.12 sec)

mysql> select * from emp;


+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
| NULL | sonu | 20000 |
| NULL | mohan | 20000 |
+------+-------+-------+
6 rows in set (0.00 sec)

mysql> insert table emp(100,"mohan",34000);


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 'table
emp(100,"mohan",34000)' at line 1
mysql> insert into table emp(100,"mohan",34000);
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 'table
emp(100,"mohan",34000)' at line 1
mysql> insert into emp values(100,'monu',34000);
Query OK, 1 row affected (0.09 sec)

mysql> select * from emp;


+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
| NULL | sonu | 20000 |
| NULL | mohan | 20000 |
| 100 | monu | 34000 |
+------+-------+-------+
7 rows in set (0.00 sec)

mysql> alter table emp add uinque key (eid);


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 'key
(eid)' at line 1
mysql> alter table emp add uinque key(eid);
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
'key(eid)' at line 1
mysql> alter table emp add unique key(eid);
ERROR 1062 (23000): Duplicate entry '100' for key 'emp.eid'
mysql> update emp set eid 104 where ename ='monu';
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 '104
where ename ='monu'' at line 1
mysql> update emp set eid=104 where ename ='monu';
Query OK, 1 row affected (0.10 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from emp;


+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
| NULL | sonu | 20000 |
| NULL | mohan | 20000 |
| 104 | monu | 34000 |
+------+-------+-------+
7 rows in set (0.00 sec)

mysql> update emp set eid=101 where ename='monu';


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

mysql> select ename table emp;


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 'table
emp' at line 1
mysql> select ename from emp;
+-------+
| ename |
+-------+
| raju |
| raju |
| nabbu |
| mohan |
| sonu |
| mohan |
| monu |
+-------+
7 rows in set (0.00 sec)

mysql> select * from emp


-> ;
+------+-------+-------+
| eid | ename | esal |
+------+-------+-------+
| 100 | raju | 30000 |
| 104 | raju | 30000 |
| 102 | nabbu | 20000 |
| 103 | mohan | 15000 |
| NULL | sonu | 20000 |
| NULL | mohan | 20000 |
| 101 | monu | 34000 |
+------+-------+-------+
7 rows in set (0.00 sec)

mysql> alter table emp add unique key (eid);


Query OK, 0 rows affected (0.99 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> insert into emp values(100,'naveen',1000);
ERROR 1062 (23000): Duplicate entry '100' for key 'emp.eid'

Enter password: ****


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.3.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ues 11to12;


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 'ues
11to12' at line 1
mysql> use 11to12;
Database changed
mysql> select date_add("2024-05-22",interval 3 day);
+---------------------------------------+
| date_add("2024-05-22",interval 3 day) |
+---------------------------------------+
| 2024-05-25 |
+---------------------------------------+
1 row in set (0.05 sec)

mysql> select date_add("2024-05-22",interval 3 month);


+-----------------------------------------+
| date_add("2024-05-22",interval 3 month) |
+-----------------------------------------+
| 2024-08-22 |
+-----------------------------------------+
1 row in set (0.04 sec)

mysql> select date_add("2024-05-22",interval 3 years);


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 'years)'
at line 1
mysql> select date_add("2024-05-22",interval 3 year);
+----------------------------------------+
| date_add("2024-05-22",interval 3 year) |
+----------------------------------------+
| 2027-05-22 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> select date_add("2024-05-22",interval -3 year);


+-----------------------------------------+
| date_add("2024-05-22",interval -3 year) |
+-----------------------------------------+
| 2021-05-22 |
+-----------------------------------------+
1 row in set (0.03 sec)

mysql> select date_add("2024-05-22",interval -3 month);


+------------------------------------------+
| date_add("2024-05-22",interval -3 month) |
+------------------------------------------+
| 2024-02-22 |
+------------------------------------------+
1 row in set (0.00 sec)

mysql> select date_add("2024-05-22",interval -3 day);


+----------------------------------------+
| date_add("2024-05-22",interval -3 day) |
+----------------------------------------+
| 2024-05-19 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> select date_sub("2024-05-22",interval 3 day);


+---------------------------------------+
| date_sub("2024-05-22",interval 3 day) |
+---------------------------------------+
| 2024-05-19 |
+---------------------------------------+
1 row in set (0.00 sec)

mysql> select date_sub("2024-05-22",interval 3 day);


+---------------------------------------+
| date_sub("2024-05-22",interval 3 day) |
+---------------------------------------+
| 2024-05-19 |
+---------------------------------------+
1 row in set (0.00 sec)

mysql> create table date_demo("my date",date),("my time",time)("mydt",datetime)


-> ;
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 '"my
date",date),("my time",time)("mydt",datetime)' at line 1
mysql> create table date_demo(mydate date,mytime time,mydt datetime);
Query OK, 0 rows affected (1.13 sec)

mysql> insert into date_demo values("1990-10-25","11:13:15","1990-10-25 11:12:05);


"> insert into date_demo values("1990-10-25","11:13:15","1990-10-25 11:12:05");
"> ^C
mysql> insert into date_demo values("1990-10-25","11:13:15","1990-10-25 11:12:05");
Query OK, 1 row affected (0.40 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
+------------+----------+---------------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql>
mysql>
mysql>
mysql> insert into date_demo values("1990-10-25","11:13:15","1990-10-25 11:12:05");
Query OK, 1 row affected (0.39 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
+------------+----------+---------------------+
2 rows in set (0.00 sec)

mysql> insert into date_demo values("70-10-25","11:13:15","1990-10-25 11:12:05");


Query OK, 1 row affected (0.08 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
+------------+----------+---------------------+
3 rows in set (0.00 sec)

mysql> insert into date_demo values("1990-10-25","11:13:15","69-10-25 11:12:05");


Query OK, 1 row affected (0.09 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
+------------+----------+---------------------+
4 rows in set (0.00 sec)

mysql> insert into date_demo values("690-10-25","11:13:15","1990-10-25 11:12:05");


Query OK, 1 row affected (0.14 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
| 0690-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
+------------+----------+---------------------+
5 rows in set (0.00 sec)

mysql> insert into date_demo values("23-10-25","11:13:15","12-10-25 11:12:05");


Query OK, 1 row affected (0.10 sec)
mysql> select * from date_demo;
+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
| 0690-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 2023-10-25 | 11:13:15 | 2012-10-25 11:12:05 |
+------------+----------+---------------------+
6 rows in set (0.00 sec)

mysql> insert into date_demo values(curdate(),curtime(),now());


Query OK, 1 row affected (0.37 sec)

mysql> select * from date_demo;


+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
| 0690-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 2023-10-25 | 11:13:15 | 2012-10-25 11:12:05 |
| 2024-05-22 | 11:30:35 | 2024-05-22 11:30:35 |
+------------+----------+---------------------+
7 rows in set (0.00 sec)

mysql> select * from emp where mydate=<2024


-> ;
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 '=<2024'
at line 1
mysql> select * from emp where mydate year =2024
-> ;
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 'year
=2024' at line 1
mysql> select * from emp where mydate < "2024'
"> ;
"> ^C
mysql> select * from emp where mydate < "2024"
-> ;
ERROR 1054 (42S22): Unknown column 'mydate' in 'where clause'
mysql> select * from date_demo where mydate < "2024"
-> ;
ERROR 1525 (HY000): Incorrect DATE value: '2024'
mysql> select * from date_demo where mydate < "2000:01:12"
-> ;
+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
| 0690-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
+------------+----------+---------------------+
5 rows in set, 1 warning (0.06 sec)

mysql> select * from date_demo where year (mydate) < "2024"


-> ;
+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1970-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
| 0690-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 2023-10-25 | 11:13:15 | 2012-10-25 11:12:05 |
+------------+----------+---------------------+
6 rows in set (0.00 sec)

mysql> select * from date_demo where year (mydate) <="1990",mydate >="2000"


-> ;
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 ',mydate
>="2000"' at line 1
mysql> select * from date_demo where year (mydate) <="1990",(mydate) >="2000"
-> ;
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 ',
(mydate) >="2000"' at line 1
mysql> select * from date_demo where year (mydate)>="1990" or <="2000"
-> ;
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
'<="2000"' at line 1
mysql> select * from date_demo where year between 1990 and 2000;
ERROR 1054 (42S22): Unknown column 'year' in 'where clause'
mysql> select * from date_demo where year(mydate) between 1990 and 2000;
+------------+----------+---------------------+
| mydate | mytime | mydt |
+------------+----------+---------------------+
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 1990-10-25 11:12:05 |
| 1990-10-25 | 11:13:15 | 2069-10-25 11:12:05 |
+------------+----------+---------------------+
3 rows in set (0.05 sec)

mysql> select * from date_demo where day(mydt)= sunday;


ERROR 1054 (42S22): Unknown column 'sunday' in 'where clause'
mysql> select * from date_demo where day(mydt)<>sunday;
ERROR 1054 (42S22): Unknown column 'sunday' in 'where clause'
mysql> select * from date_demo where dayname(mydt)="sunday" ;
Empty set (0.06 sec)

mysql> select * from date_demo where dayname(mydt)="sunday";


Empty set (0.00 sec)

mysql> select count (esal)from emp;


ERROR 1630 (42000): FUNCTION 11to12.count does not exist. Check the 'Function Name
Parsing and Resolution' section in the Reference Manual
mysql> select count(esal)from emp;
+-------------+
| count(esal) |
+-------------+
| 7 |
+-------------+
1 row in set (0.06 sec)

mysql> select count(ei)from emp;


ERROR 1054 (42S22): Unknown column 'ei' in 'field list'
mysql> select count(eid)from emp;
+------------+
| count(eid) |
+------------+
| 8 |
+------------+
1 row in set (0.00 sec)

mysql> select * from emp;


+-----+--------+------+-------+---------+
| eid | ename | exp | esal | edept |
+-----+--------+------+-------+---------+
| 90 | naveen | 0 | NULL | account |
| 100 | chinu | 5 | 20000 | coding |
| 101 | bhoul | 5 | 15000 | coding |
| 102 | millu | 5 | 15000 | coding |
| 104 | raghu | 5 | 10000 | coding |
| 112 | varun | 8 | 30000 | hr |
| 113 | babu | 8 | 50000 | gh |
| 114 | sabhu | 6 | 40000 | ph |
+-----+--------+------+-------+---------+
8 rows in set (0.00 sec)

mysql> select count(*)from emp;


+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> insert into emp esal values (25000)where eid =90;
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 'esal
values (25000)where eid =90' at line 1
mysql> insert into emp values esal (25000)where eid =90;
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 'esal
(25000)where eid =90' at line 1
mysql> update emp set esal=25000 where esal is null;
Query OK, 1 row affected (0.40 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select*from emp;


+-----+--------+------+-------+---------+
| eid | ename | exp | esal | edept |
+-----+--------+------+-------+---------+
| 90 | naveen | 0 | 25000 | account |
| 100 | chinu | 5 | 20000 | coding |
| 101 | bhoul | 5 | 15000 | coding |
| 102 | millu | 5 | 15000 | coding |
| 104 | raghu | 5 | 10000 | coding |
| 112 | varun | 8 | 30000 | hr |
| 113 | babu | 8 | 50000 | gh |
| 114 | sabhu | 6 | 40000 | ph |
+-----+--------+------+-------+---------+
8 rows in set (0.00 sec)

mysql>
mysql>

You might also like