Practical 2

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 10

NAME: SANDIP PAWAR

CLASS : TE
DIV : C

Practical 2

Problem Statement : Design and develp SQL-DDL statements which demostrate the
use of SQL object such as table, view, index, sequence, synonym.

Output
CREATE DATABASE

mysql> create database college2;


Query OK, 1 row affected (0.12 sec)

CREATE TABLE

mysql> create table colleges(id int, address varchar(30), pin int);


Query OK, 0 rows affected (0.42 sec)

mysql> DESC colleges;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
| pin | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

INSERT RECORD INTO TABLE

mysql> insert into colleges (id, address, pin) values (1,"Pune",23456),


(2,"Solapur",45674),(3,"Mumbai",67855),(4,"Rahuri",67864),(5,"Dapoli",68965);
Query OK, 5 rows affected (0.09 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> DESC colleges;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
| pin | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> selec * from colleges;


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 'selec *
from colleges' at line 1
mysql> select * from colleges;
+------+---------+-------+
| id | address | pin |
+------+---------+-------+
| 1 | Pune | 23456 |
| 2 | Solapur | 45674 |
| 3 | Mumbai | 67855 |
| 4 | Rahuri | 67864 |
| 5 | Dapoli | 68965 |
+------+---------+-------+
5 rows in set (0.00 sec)

UPDATE RECORDS

mysql> update colleges set (address="Nagpur" where id=2;


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
'(address="Nagpur" where id=2' at line 1
mysql> update colleges set address="Nagpur" where id=2;
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from colleges;


+------+---------+-------+
| id | address | pin |
+------+---------+-------+
| 1 | Pune | 23456 |
| 2 | Nagpur | 45674 |
| 3 | Mumbai | 67855 |
| 4 | Rahuri | 67864 |
| 5 | Dapoli | 68965 |
+------+---------+-------+
5 rows in set (0.00 sec)

DELETE RECORD
mysql> delete from colleges where id=3;
Query OK, 1 row affected (0.12 sec)

mysql> select * from colleges;


+------+---------+-------+
| id | address | pin |
+------+---------+-------+
| 1 | Pune | 23456 |
| 2 | Nagpur | 45674 |
| 4 | Rahuri | 67864 |
| 5 | Dapoli | 68965 |
+------+---------+-------+
4 rows in set (0.00 sec)

RENAME TABLE

mysql> rename table colleges to address;


Query OK, 0 rows affected (0.23 sec)

mysql> select * from colleges;


ERROR 1146 (42S02): Table 'college2.colleges' doesn't exist
mysql> select * from address;
+------+---------+-------+
| id | address | pin |
+------+---------+-------+
| 1 | Pune | 23456 |
| 2 | Nagpur | 45674 |
| 4 | Rahuri | 67864 |
| 5 | Dapoli | 68965 |
+------+---------+-------+
4 rows in set (0.00 sec)

TRUNCATE TABLE

mysql> truncate table address;


Query OK, 0 rows affected (0.74 sec)

mysql> select * from address;


Empty set (0.00 sec)

DROP TABLE

mysql> drop table address;


Query OK, 0 rows affected (0.25 sec)

mysql> select * from address;


ERROR 1146 (42S02): Table 'college2.address' doesn't exist

d-comp-dbms-1-07@dcompdbms107-OptiPlex-3070:~$ sudo mysql


[sudo] password for d-comp-dbms-1-07:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.33-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

SHOW DATABASE

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| college |
| college1 |
| college2 |
| college_info |
| darkside |
| dbms |
| dbms1 |
| sandip |
| hello |
| info |
| information |
| information_schema |
| mysql |
| performance_schema |
| prac6 |
| practical6 |
| stud_info |
| student |
| sys |
| university |
| vp |
+--------------------+
21 rows in set (0.00 sec)

USE DATABASE
mysql> use sandip;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

SHOW TABLES

mysql> show tables;


+-------------------+
| Tables_in_sandip|
+-------------------+
| student |
+-------------------+
1 row in set (0.00 sec)

CREATED STRUCTURE(TABLE)

mysql> DESC student;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| roll_no | int | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| class | varchar(5) | YES | | NULL | |
| age | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

INSERT DATA INTO TABLE

mysql> insert into student (roll_no,name,class,age)values(1,'ram','BE',20),


(2,'madhav','BE',20),(3,'siya','TE',19);
Query OK, 3 rows affected (0.10 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from student;


+---------+--------+-------+------+
| roll_no | name | class | age |
+---------+--------+-------+------+
| 1 | ram | BE | 20 |
| 2 | madhav | BE | 20 |
| 3 | siya | TE | 19 |
+---------+--------+-------+------+
3 rows in set (0.00 sec)

ALTER COLUMN

mysql> alter table student add branch varchar(30);


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

mysql> select * from student;


+---------+--------+-------+------+--------+
| roll_no | name | class | age | branch |
+---------+--------+-------+------+--------+
| 1 | ram | BE | 20 | NULL |
| 2 | madhav | BE | 20 | NULL |
| 3 | siya | TE | 19 | NULL |
+---------+--------+-------+------+--------+
3 rows in set (0.00 sec)

UPDATE COLUMN

mysql> update student set branch='computer';


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

mysql> select * from student;


+---------+--------+-------+------+----------+
| roll_no | name | class | age | branch |
+---------+--------+-------+------+----------+
| 1 | ram | BE | 20 | computer |
| 2 | madhav | BE | 20 | computer |
| 3 | siya | TE | 19 | computer |
+---------+--------+-------+------+----------+
3 rows in set (0.00 sec)

mysql> update student set branch='mechinical' where roll_no=2;


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

mysql> select * from student;


+---------+--------+-------+------+------------+
| roll_no | name | class | age | branch |
+---------+--------+-------+------+------------+
| 1 | ram | BE | 20 | computer |
| 2 | madhav | BE | 20 | mechinical |
| 3 | siya | TE | 19 | computer |
+---------+--------+-------+------+------------+
3 rows in set (0.00 sec)

DROP (ALTER)
mysql> alter table student drop age;
Query OK, 0 rows affected (0.26 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from student;


+---------+--------+-------+------------+
| roll_no | name | class | branch |
+---------+--------+-------+------------+
| 1 | ram | BE | computer |
| 2 | madhav | BE | mechinical |
| 3 | siya | TE | computer |
+---------+--------+-------+------------+
3 rows in set (0.00 sec)

RENAME COLUMN NAME

mysql> alter table student change class study_in varchar (5);


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

mysql> select * from student;


+---------+--------+----------+------------+
| roll_no | name | study_in | branch |
+---------+--------+----------+------------+
| 1 | ram | BE | computer |
| 2 | madhav | BE | mechinical |
| 3 | siya | TE | computer |
+---------+--------+----------+------------+
3 rows in set (0.00 sec)

CREATE VIEW

mysql> create view stud as select roll_no,name from student;


Query OK, 0 rows affected (0.10 sec)
mysql> select * from stud;
+---------+--------+
| roll_no | name |
+---------+--------+
| 1 | ram |
| 2 | madhav |
| 3 | siya |
+---------+--------+
3 rows in set (0.00 sec)
DROP VIEW
mysql> drop view stud;
Query OK, 0 rows affected (0.11 sec)

mysql> select * from stud;


ERROR 1146 (42S02): Table 'sandip.stud' doesn't exist

CREATE INDEX

mysql> create index index1 on student(roll_no, branch);


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

SHOW INDEX

mysql> show index from student;


+---------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation |
Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
Visible | Expression |
+---------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+---------------+---------+------------+
| student | 1 | index1 | 1 | roll_no | A | 3 | NULL | NULL
| YES | BTREE | | | YES | NULL |
| student | 1 | index1 | 2 | branch |A | 3 | NULL |
NULL | YES | BTREE | | | YES | NULL |
+---------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+---------------+---------+------------+
2 rows in set (0.08 sec)

DROP INDEX

mysql> alter table student drop index index1;


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

mysql> show index from student;


Empty set (0.00 sec)
CREATE SYNONYM

mysql> call sys.create_synonym_db ('sandip','me_sandip');


+---------------------------------------------+
| summary |
+---------------------------------------------+
| Created 1 view in the `me_sandip` database |
+---------------------------------------------+
1 row in set (0.24 sec)

Query OK, 0 rows affected (0.24 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| college |
| college1 |
| college2 |
| college_info |
| darkside |
| dbms |
| dbms1 |
| hello |
| info |
| information |
| information_schema |
| me_sandip |
| mysql |
| performance_schema |
| prac6 |
| practical6 |
| stud_info |
| student |
| sys |
| university |
| vp |
+--------------------+
22 rows in set (0.00 sec)

mysql>

SEQUENCE CREATE
mysql> create table college (roll_no int not null auto_increment, name varchar(20),
age int, primary key(roll_no));
Query OK, 0 rows affected (0.42 sec)

mysql> create table college1 (roll_no int not null auto_increment, name varchar(20),
year_established int, primary key(roll_no));
Query OK, 0 rows affected (1.05 sec)

INSERT INTO SEQUENCE

mysql> insert into college1 (name, year_established) values ('zeal',2010),


('coep',1999),('pecoe',1999);
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0

SHOW SEQUENCE

+---------+-------+------------------+
| roll_no | name | year_established |
+---------+-------+------------------+
| 1 | zeal | 2010 |
| 2 | coep | 1999 |
| 3 | pecoe | 1999 |
+---------+-------+------------------+
3 rows in set (0.00 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