0% found this document useful (0 votes)
14 views7 pages

Harsh Sharma Mysql PG-1

The document outlines a series of MySQL commands to create a database and a 'teacher' table, including the insertion, updating, and deletion of records. It also demonstrates how to alter the table structure and perform various queries to retrieve specific data. Additionally, a 'sales' table is created at the end of the document.

Uploaded by

gamer021903s
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)
14 views7 pages

Harsh Sharma Mysql PG-1

The document outlines a series of MySQL commands to create a database and a 'teacher' table, including the insertion, updating, and deletion of records. It also demonstrates how to alter the table structure and perform various queries to retrieve specific data. Additionally, a 'sales' table is created at the end of the document.

Uploaded by

gamer021903s
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/ 7

mysql> create database xiid0232;

Query OK, 1 row affected (0.01 sec)

mysql> use xiid0232;

Database changed

mysql> create table teacher

-> (

-> teacher_id integer primary key,

-> first_name varchar(20) not null,

-> last_name varchar(20),

-> gender char(1),

-> salary decimal(10,2) default 40000,

-> dob date,

-> dept_no integer

-> );

Query OK, 0 rows affected (0.01 sec)

mysql> desc teacher;

+------------+---------------+------+-----+----------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------+---------------+------+-----+----------+-------+

| teacher_id | int | NO | PRI | NULL | |

| first_name | varchar(20) | NO | | NULL | |

| last_name | varchar(20) | YES | | NULL | |

| gender | char(1) | YES | | NULL | |

| salary | decimal(10,2) | YES | | 40000.00 | |

| dob | date | YES | | NULL | |

| dept_no | int | YES | | NULL | |

+------------+---------------+------+-----+----------+-------+

7 rows in set (0.01 sec)


mysql> insert into teacher

-> values

-> (101,"rythm","garg","f",10000,"2001-02-07",11);

Query OK, 1 row affected (0.01 sec)

mysql> insert into teacher

-> (teacher_id,first_name,last_name,gender,dob,dept_no)

-> values

-> (102,"priyanshi","kaushik","f","2000-04-05",12);

Query OK, 1 row affected (0.00 sec)

mysql> select * from teacher;

+------------+------------+-----------+--------+----------+------------+---------+

| teacher_id | first_name | last_name | gender | salary | dob | dept_no |

+------------+------------+-----------+--------+----------+------------+---------+

| 101 | rythm | garg |f | 10000.00 | 2001-02-07 | 11 |

| 102 | priyanshi | kaushik | f | 40000.00 | 2000-04-05 | 12 |

+------------+------------+-----------+--------+----------+------------+---------+

2 rows in set (0.00 sec)

mysql> alter table teacher

-> add age integer;

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc teacher;

+------------+---------------+------+-----+----------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------+---------------+------+-----+----------+-------+

| teacher_id | int | NO | PRI | NULL | |

| first_name | varchar(20) | NO | | NULL | |


| last_name | varchar(20) | YES | | NULL | |

| gender | char(1) | YES | | NULL | |

| salary | decimal(10,2) | YES | | 40000.00 | |

| dob | date | YES | | NULL | |

| dept_no | int | YES | | NULL | |

| age | int | YES | | NULL | |

+------------+---------------+------+-----+----------+-------+

8 rows in set (0.00 sec)

mysql> select * from teacher;

+------------+------------+-----------+--------+----------+------------+---------+------+

| teacher_id | first_name | last_name | gender | salary | dob | dept_no | age |

+------------+------------+-----------+--------+----------+------------+---------+------+

| 101 | rythm | garg |f | 10000.00 | 2001-02-07 | 11 | NULL |

| 102 | priyanshi | kaushik | f | 40000.00 | 2000-04-05 |

12 | NULL |

+------------+------------+-----------+--------+----------+------------+---------+------+

2 rows in set (0.00 sec)

mysql> ALTER TABLE TEACHER

-> DROP AGE;

Query OK, 0 rows affected (0.01 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc teacher;

+------------+---------------+------+-----+----------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------+---------------+------+-----+----------+-------+

| teacher_id | int | NO | PRI | NULL | |

| first_name | varchar(20) | NO | | NULL | |

| last_name | varchar(20) | YES | | NULL | |


| gender | char(1) | YES | | NULL | |

| salary | decimal(10,2) | YES | | 40000.00 | |

| dob | date | YES | | NULL | |

| dept_no | int | YES | | NULL | |

+------------+---------------+------+-----+----------+-------+

7 rows in set (0.00 sec)

mysql> update teacher

-> set salary=70000

-> where teacher_id=101;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from teacher;

+------------+------------+-----------+--------+----------+------------+---------+

| teacher_id | first_name | last_name | gender | salary | dob | dept_no |

+------------+------------+-----------+--------+----------+------------+---------+

| 101 | rythm | garg |f | 70000.00 | 2001-02-07 | 11 |

| 102 | priyanshi | kaushik | f | 40000.00 | 2000-04-05 | 12 |

+------------+------------+-----------+--------+----------+------------+---------+

2 rows in set (0.00 sec)

mysql> delete from teacher where teacher_id=101;

Query OK, 1 row affected (0.00 sec)

mysql> select * from teacher;

+------------+------------+-----------+--------+----------+------------+---------+

| teacher_id | first_name | last_name | gender | salary | dob | dept_no |

+------------+------------+-----------+--------+----------+------------+---------+

| 102 | priyanshi | kaushik | f | 40000.00 | 2000-04-05 | 12 |

+------------+------------+-----------+--------+----------+------------+---------+
1 row in set (0.00 sec)

mysql> insert into teacher

-> values

-> (103,"sapna","potaliya","f",30000,"2003-06-07",13);

Query OK, 1 row affected (0.00 sec)

mysql> select distinct dept_no

-> from teacher

-> where gender='f';

+---------+

| dept_no |

+---------+

| 12 |

| 13 |

+---------+

2 rows in set (0.00 sec)

mysql> select first_name

-> from teacher

-> where first_name like 's%';

+------------+

| first_name |

+------------+

| sapna |

+------------+

1 row in set (0.00 sec)

mysql> select * from teacher;

+------------+------------+-----------+--------+----------+------------+---------+

| teacher_id | first_name | last_name | gender | salary | dob | dept_no |


+------------+------------+-----------+--------+----------+------------+---------+

| 102 | priyanshi | kaushik | f | 40000.00 | 2000-04-05 | 12 |

| 103 | sapna | potaliya | f | 30000.00 | 2003-06-07 | 13 |

+------------+------------+-----------+--------+----------+------------+---------+

2 rows in set (0.00 sec)

mysql> select first_name

-> from teacher

-> order by salary;

+------------+

| first_name |

+------------+

| sapna |

| priyanshi |

+------------+

2 rows in set (0.00 sec)

mysql> select first_name

-> from teacher

-> order by salary desc;

+------------+

| first_name |

+------------+

| priyanshi |

| sapna |

+------------+

2 rows in set (0.00 sec)

mysql> create table sales

-> (

-> machine_id char(3),


-> date_1 date,

-> tickets_sold integer,

-> income decimal(8,2),

-> primary key(machine_id,date_1)

-> );

Query OK, 0 rows affected (0.01 sec)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy