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

MySQL Database and Table Management

The document outlines the process of creating a MySQL database named 'GEAR' and a table 'SCHOOL_BAGS' with various product attributes. It includes inserting multiple records into the table and demonstrates the use of the ALTER command to add a new column and rename the table to 'SCHOOL_BAG'. The document concludes with a description of the modified table structure.

Uploaded by

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

MySQL Database and Table Management

The document outlines the process of creating a MySQL database named 'GEAR' and a table 'SCHOOL_BAGS' with various product attributes. It includes inserting multiple records into the table and demonstrates the use of the ALTER command to add a new column and rename the table to 'SCHOOL_BAG'. The document concludes with a description of the modified table structure.

Uploaded by

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

AIM:- CREATE , DATABASE AND PRODUCT TABLE IN DATABASE AND

INSERT VALUES INTO TABLE.

MySQL> create database GEAR;

Query OK, 1 row affected (0.308 sec)

mysql> USE GEAR;

Database changed

mysql> CREATE TABLE SCHOOL_BAGS(PRODUCT_NO INT(23),PRODUCT_NAME


VARCHAR(24),PRODUCT_PRICE INT(20),PRODUCT_WARRANTY INT(20));

Query OK, 0 rows affected, 3 warnings (1.060 sec)

mysql> DESC SCHOOL_BAGS;

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

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

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

| PRODUCT_NO | int | YES | | NULL | |

| PRODUCT_NAME | varchar(24) | YES | | NULL | |

| PRODUCT_PRICE | int | YES | | NULL | |

| PRODUCT_WARRANTY | int | YES | | NULL | |

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

4 rows in set (0.652 sec)

mysql> INSERT INTO SCHOOL_BAGS VALUES(1,'POLESTER_BAGS',299,2);

Query OK, 1 row affected (0.253 sec)

mysql> INSERT INTO SCHOOL_BAGS VALUES(2,'COTTON_BAGS',799,2);


Query OK, 1 row affected (0.113 sec)

mysql> INSERT INTO SCHOOL_BAGS VALUES(3,'LEATHER_BAGS',2399,2);

Query OK, 1 row affected (0.039 sec)

mysql> INSERT INTO SCHOOL_BAGS VALUES(4,'CELEBRITY_BAGS',12000,2);

Query OK, 1 row affected (0.111 sec)

mysql> INSERT INTO SCHOOL_BAGS VALUES(5,'ELECTRIC_BAGS',1299,2);

Query OK, 1 row affected (0.090 sec)

mysql> SELECT * FROM SCHOOL_BAGS;

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

| PRODUCT_NO | PRODUCT_NAME | PRODUCT_PRICE | PRODUCT_WARRANTY |

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

| 1 | POLESTER_BAGS | 299 | 2|

| 2 | COTTON_BAGS | 799 | 2|

| 3 | LEATHER_BAGS | 2399 | 2|

| 4 | CELEBRITY_BAGS | 12000 | 2|

| 5 | ELECTRIC_BAGS | 1299 | 2|

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

5 rows in set (0.037 sec)


AIM :– ALTER COMMAND ON TABLE RENAME,DROPPING, AND
MODIFYING THE COLUMNS

mysql> ALTER TABLE SCHOOL_BAGS ADD(PRODUCT_SIZE INT(12));

Query OK, 0 rows affected, 1 warning (0.501 sec)

Records: 0 Duplicates: 0 Warnings: 1

mysql> DESC SCHOOL_BAGS;

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

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

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

| PRODUCT_NO | int | YES | | NULL | |

| PRODUCT_NAME | varchar(24) | YES | | NULL | |

| PRODUCT_PRICE | int | YES | | NULL | |

| PRODUCT_WARRANTY | int | YES | | NULL | |

| PRODUCT_SIZE | int | YES | | NULL | |

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

5 rows in set (0.049 sec)


mysql> RENAME TABLE SCHOOL_BAGS TO SCHOOL_BAG;

Query OK, 0 rows affected (0.334 sec)

mysql> DESC SCHOOL_BAG;

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

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

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

| PRODUCT_NO | int | NO | PRI | NULL | |

| PRODUCT_NAME | varchar(24) | YES | | NULL | |

| PRODUCT_PRICE | int | YES | | NULL | |

| PRODUCT_SIZE | int | YES | | NULL | |

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

4 rows in set (0.044 sec))

mysql> RENAME TABLE SCHOOL_BAGS TO SCHOOL_BAG;

Query OK, 0 rows affected (0.334 sec)

mysql> DESC SCHOOL_BAG;

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

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

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

| PRODUCT_NO | int | NO | PRI | NULL | |

| PRODUCT_NAME | varchar(24) | YES | | NULL | |

| PRODUCT_PRICE | int | YES | | NULL | |

| PRODUCT_SIZE | int | YES | | NULL | |

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

CREATED BY RONAK YADAV

You might also like