Lab Assignment 1
Name :Shravani Kavle Class :TE AIDS
Roll No:T23134 Batch:T2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| bank |
| cpp |
| dbms |
| information_schema |
| mysql |
| new |
| performance_schema |
| sys |
+--------------------+
8 rows in set (0.09 sec)
mysql> create database College;
Query OK, 1 row affected (0.04 sec)
mysql> use College;
Database changed
mysql> create table Student(RN int primary key,sname varchar(50) not null, address
varchar(50),age int);
Query OK, 0 rows affected (0.08 sec)
mysql> desc 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> desc Student;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| RN | int | NO | PRI | NULL | |
| sname | varchar(50) | NO | | NULL | |
| address | varchar(50) | YES | | NULL | |
| age | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)
mysql> create table Subject(sub_code int primary key,sub_name varchar(50) not null);
Query OK, 0 rows affected (0.04 sec)
mysql> desc Subject;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| sub_code | int | NO | PRI | NULL | |
| sub_name | varchar(50) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> create table Subject(Rollno int ,scode int , foreign key (Rollno) references
Student(RN), foreign key (scode) references Subject(Sub_code));
ERROR 1050 (42S01): Table 'subject' already exists
mysql> drop table subject;
Query OK, 0 rows affected (0.03 sec)
mysql> drop table subject;
ERROR 1051 (42S02): Unknown table '[Link]'
mysql> create table Subject(sub_code int primary key,sub_name varchar(50) not null);
Query OK, 0 rows affected (0.05 sec)
mysql> desc Subject;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| sub_code | int | NO | PRI | NULL | |
| sub_name | varchar(50) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> create table Result(Rollno int ,scode int , marks int, foreign key (Rollno) references
Student(RN), foreign key (scode) references Subject(Sub_code));
Query OK, 0 rows affected (0.08 sec)
mysql> desc Result;
+--------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------+------+-----+---------+-------+
| Rollno | int | YES | MUL | NULL | |
| scode | int | YES | MUL | NULL | |
| marks | int | YES | | NULL | |
+--------+------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> Alter table sStudent rename sname to std_name;
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 'to std_name' at
line 1
mysql> Alter table sStudent rename sname to std_name varchar(50);
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 'to std_name
varchar(50)' at line 1
mysql> Alter table Student rename sname to std_name varchar(50);
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 'to std_name
varchar(50)' at line 1
mysql> Alter table Student rename column sname to std_name varchar(50);
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 'varchar(50)' at
line 1
mysql> Alter table Student rename column sname to std_name ;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc Student;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| RN | int | NO | PRI | NULL | |
| std_name | varchar(50) | NO | | NULL | |
| address | varchar(50) | YES | | NULL | |
| age | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> insert into Student
values(701,"jay","pune",21),(702,"kai","Goa",23),(704,"Sam","Pune",25);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> insert into Subject values(23134,"DBMS"), (23166,"Python");
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into Marks values(701,23134,67),(702,23166,56);
ERROR 1146 (42S02): Table '[Link]' doesn't exist
mysql> insert into Result values(701,23134,67),(702,23166,56);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from Student;
+-----+----------+---------+------+
| RN | std_name | address | age |
+-----+----------+---------+------+
| 701 | jay | pune | 21 |
| 702 | kai | Goa | 23 |
| 704 | Sam | Pune | 25 |
+-----+----------+---------+------+
3 rows in set (0.00 sec)
mysql> select * from Subject;
+----------+----------+
| sub_code | sub_name |
+----------+----------+
| 23134 | DBMS |
| 23166 | Python |
+----------+----------+
2 rows in set (0.00 sec)
mysql> select * from Result;
+--------+-------+-------+
| Rollno | scode | marks |
+--------+-------+-------+
| 701 | 23134 | 67 |
| 702 | 23166 | 56 |
+--------+-------+-------+
2 rows in set (0.00 sec)
mysql> update student set RN=703 where std_name="Sam";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Student;
+-----+----------+---------+------+
| RN | std_name | address | age |
+-----+----------+---------+------+
| 701 | jay | pune | 21 |
| 702 | kai | Goa | 23 |
| 703 | Sam | Pune | 25 |
+-----+----------+---------+------+
3 rows in set (0.00 sec)
mysql> select * from Student where age>=24 and address="Pune";
+-----+----------+---------+------+
| RN | std_name | address | age |
+-----+----------+---------+------+
| 703 | Sam | Pune | 25 |
+-----+----------+---------+------+
1 row in set (0.00 sec)
mysql> delete from student where ade =23;
ERROR 1054 (42S22): Unknown column 'ade' in 'where clause'
mysql> delete from student where age =23;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
(`college`.`result`, CONSTRAINT `result_ibfk_1` FOREIGN KEY (`Rollno`) REFERENCES
`student` (`RN`))
mysql> truncate from student where age =23;
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 student
where age =23' at line 1
mysql> DELETE FROM Student WHERE age = 23;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
(`college`.`result`, CONSTRAINT `result_ibfk_1` FOREIGN KEY (`Rollno`) REFERENCES
`student` (`RN`))
mysql> create table stud select * from student;
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql> DELETE FROM stud WHERE age = 23;
Query OK, 1 row affected (0.01 sec)
mysql> desc stud;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| RN | int | NO | | NULL | |
| std_name | varchar(50) | NO | | NULL | |
| address | varchar(50) | YES | | NULL | |
| age | int | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select *from stud;
+-----+----------+---------+------+
| RN | std_name | address | age |
+-----+----------+---------+------+
| 701 | jay | pune | 21 |
| 703 | Sam | Pune | 25 |
+-----+----------+---------+------+
2 rows in set (0.00 sec)
mysql> truncate table stud;
Query OK, 0 rows affected (0.07 sec)
mysql> select *from stud;
Empty set (0.00 sec)
mysql> delete table stud;
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 stud' at line
1
mysql> drop table stud;
Query OK, 0 rows affected (0.03 sec)
mysql> select *from stud;
ERROR 1146 (42S02): Table '[Link]' doesn't exist
mysql>