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

TABLE 1

The document details the process of creating a database and a table named 'STUDENT' in MySQL, including the structure of the table and the insertion of student records. It also includes examples of SQL queries for updating student information, viewing data in different orders, and eliminating redundant data. The table consists of fields such as roll number, name, date of birth, subject scores, grade, and last name.

Uploaded by

jangratanisha26
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)
8 views

TABLE 1

The document details the process of creating a database and a table named 'STUDENT' in MySQL, including the structure of the table and the insertion of student records. It also includes examples of SQL queries for updating student information, viewing data in different orders, and eliminating redundant data. The table consists of fields such as roll number, name, date of birth, subject scores, grade, and last name.

Uploaded by

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

Creating Database and Table 1

mysql> CREATE DATABASE STUDENT;


Query OK, 1 row affected (0.01 sec)

mysql> USE STUDENT;


Database changed

mysql> CREATE TABLE STUDENT (SROLLNO INT NOT NULL, SNAME VARCHAR (20) NOT
NULL, SDOB DATE, SENGLISH INT(2), SMATH INT(2), SCOMPUTERS INT(2),
-> SSCIENCE INT(2), GRADE VARCHAR(2), SLASTNAME VARCHAR(10));
Query OK, 0 rows affected, 4 warnings (0.03 sec)

mysql> DESC STUDENT;

+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| SROLLNO | int | NO | | NULL | |
| SNAME | varchar(20) | NO | | NULL | |
| SDOB | date | YES | | NULL | |
| SENGLISH | int | YES | | NULL | |
| SMATH | int | YES | | NULL | |
| SCOMPUTERS | int | YES | | NULL | |
| SSCIENCE | int | YES | | NULL | |
| GRADE | varchar(2) | YES | | NULL | |
| SLASTNAME | varchar(10) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

INSERTING DATA IN TABLE


mysql> INSERT INTO STUDENT VALUES(1001, 'AMIT', 20000122, 56, 78, 87, 76,
'B', 'KAPUR');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO STUDENT VALUES(1002, 'DIVYA', 20010509, 65, 85, 45, 67,
'B', 'NULL');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO STUDENT VALUES (1003, 'PIYUSH', 20010312, 67, 75, 89, 77,
'A', 'NULL');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO STUDENT VALUES (1004, 'AMAN', 20020919, 56, 57, 55, 45,
'C', 'NULL');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO STUDENT VALUES (1005, 'KAVITA', 20010312, 89, 76, 84, 75,
'A', 'NULL');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO STUDENT VALUES (1006, 'HEENA', 20000609, 67, 45, 43, 34,
'C', 'MIRZA');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO STUDENT VALUES (1007, 'SUMAN', 20010302, 45, 65, 34, 67,
'C', 'KUMARI');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO STUDENT VALUES (1008, 'RAVI', 20000905, 86, 87, 92, 89,
'A', 'KUMAR');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM STUDENT;

+---------+--------+------------+----------+-------+------------+----------
+-------+-----------+
| SROLLNO | SNAME | SDOB | SENGLISH | SMATH | SCOMPUTERS | SSCIENCE |
GRADE | SLASTNAME |
+---------+--------+------------+----------+-------+------------+----------
+-------+-----------+
| 1001 | AMIT | 2000-01-22 | 56 | 78 | 87 | 76 |
B | KAPUR |
| 1002 | DIVYA | 2001-05-09 | 65 | 85 | 45 | 67 |
B | NULL |
| 1003 | PIYUSH | 2001-03-12 | 67 | 75 | 89 | 77 |
A | NULL |
| 1004 | AMAN | 2002-09-19 | 56 | 57 | 55 | 45 |
C | NULL |
| 1005 | KAVITA | 2001-03-12 | 89 | 76 | 84 | 75 |
A | NULL |
| 1006 | HEENA | 2000-06-09 | 67 | 45 | 43 | 34 |
C | MIRZA |
| 1007 | SUMAN | 2001-03-02 | 45 | 65 | 34 | 67 |
C | KUMARI |
| 1008 | RAVI | 2000-09-05 | 86 | 87 | 92 | 89 |
A | KUMAR |
+---------+--------+------------+----------+-------+------------+----------
+-------+-----------+
8 rows in set (0.00 sec)

Queries
1. Updating Student Lastname

mysql> UPDATE STUDENT SET SLASTNAME= 'KAPUR' WHERE SROLLNO=1001;


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

+---------+-------+------------+----------+-------+------------+----------+-------
+-----------+
| SROLLNO | SNAME | SDOB | SENGLISH | SMATH | SCOMPUTERS | SSCIENCE | GRADE |
SLASTNAME |
+---------+-------+------------+----------+-------+------------+----------+-------
+-----------+
| 1001 | AMIT | 2000-01-22 | 56 | 78 | 87 | 76 | B | KAPUR
|
+---------+-------+------------+----------+-------+------------+----------+-------
+-----------+

2. Updating Date Of Birth

mysql> UPDATE STUDENT SET SDOB= 20000215 WHERE SROLLNO=1003;


Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
3. Viewing Table in Descending Order

mysql> SELECT * FROM STUDENT ORDER BY SROLLNO DESC;

4. Viewing Data of Only One Student

mysql> SELECT * FROM STUDENT WHERE SNAME LIKE 'P%';

5. Eliminating Redundant Data

mysql> SELECT DISTINCT SLASTNAME FROM STUDENT;

You might also like