0% found this document useful (0 votes)
5 views4 pages

Mysql Queries

For job

Uploaded by

who534154
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)
5 views4 pages

Mysql Queries

For job

Uploaded by

who534154
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/ 4

Enter password: ****

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


Your MySQL connection id is 1
Server version: 5.5.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

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> create database mark;


Query OK, 1 row affected (0.00 sec)

mysql> use mark;


Database changed
mysql> create table mark1(Sname varchar(20),regno int,std int,);
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> create table mark1(Sname varchar(20),regno int,std int,tamil int,english
int,maths int,science int,social int);
Query OK, 0 rows affected (0.02 sec)

mysql> desc mark1;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| Sname | varchar(20) | YES | | NULL | |
| regno | int(11) | YES | | NULL | |
| std | int(11) | YES | | NULL | |
| tamil | int(11) | YES | | NULL | |
| english | int(11) | YES | | NULL | |
| maths | int(11) | YES | | NULL | |
| science | int(11) | YES | | NULL | |
| social | int(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
8 rows in set (0.01 sec)

mysql> insert into mark1 values('Skandha',12124,10,87,89,90,95,96);


Query OK, 1 row affected (0.00 sec)

mysql> select * from mark1;


+---------+-------+------+-------+---------+-------+---------+--------+
| Sname | regno | std | tamil | english | maths | science | social |
+---------+-------+------+-------+---------+-------+---------+--------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 |
+---------+-------+------+-------+---------+-------+---------+--------+
1 row in set (0.00 sec)

mysql> insert into mark1 values('vedha',12125,10,78,87,76,95,94),


('Arulselvam',12125,10,87,89,94,94,90);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+
| Sname | regno | std | tamil | english | maths | science | social |
+------------+-------+------+-------+---------+-------+---------+--------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 |
| Arulselvam | 12125 | 10 | 87 | 89 | 94 | 94 | 90 |
+------------+-------+------+-------+---------+-------+---------+--------+
3 rows in set (0.00 sec)

mysql> alter table mark1 add total int,add average decimal(5,2);


Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | NULL |
NULL |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | NULL |
NULL |
| Arulselvam | 12125 | 10 | 87 | 89 | 94 | 94 | 90 | NULL |
NULL |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set total=tamil+english+maths+science+social where regno=12124;


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

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
NULL |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | NULL |
NULL |
| Arulselvam | 12125 | 10 | 87 | 89 | 94 | 94 | 90 | NULL |
NULL |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set total=tamil+english+maths+science+social where regno=12125;


Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
NULL |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | 430 |
NULL |
| Arulselvam | 12125 | 10 | 87 | 89 | 94 | 94 | 90 | 454 |
NULL |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set average=total/5;


Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
91.40 |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | 430 |
86.00 |
| Arulselvam | 12125 | 10 | 87 | 89 | 94 | 94 | 90 | 454 |
90.80 |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set Sname='Arul' where regno=12125;


Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select * from mark1;


+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
91.40 |
| Arul | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | 430 |
86.00 |
| Arul | 12125 | 10 | 87 | 89 | 94 | 94 | 90 | 454 |
90.80 |
+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set Sname='Arulselvam' where regno=12125;


Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> update mark1 set regno=12126 where average=90.80;


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

mysql> update mark1 set name='vedha' where regno=12125;


ERROR 1054 (42S22): Unknown column 'name' in 'field list'
mysql> update mark1 set Sname='vedha' where regno=12125;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from mark1;


+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
91.40 |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | 430 |
86.00 |
| Arulselvam | 12126 | 10 | 87 | 89 | 94 | 94 | 90 | 454 |
90.80 |
+------------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql> update mark1 set Sname='Arul' where regno=12126;


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

mysql> select * from mark1;


+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Sname | regno | std | tamil | english | maths | science | social | total |
average |
+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
| Skandha | 12124 | 10 | 87 | 89 | 90 | 95 | 96 | 457 |
91.40 |
| vedha | 12125 | 10 | 78 | 87 | 76 | 95 | 94 | 430 |
86.00 |
| Arul | 12126 | 10 | 87 | 89 | 94 | 94 | 90 | 454 |
90.80 |
+---------+-------+------+-------+---------+-------+---------+--------+-------
+---------+
3 rows in set (0.00 sec)

mysql>

You might also like