Adt Lab Record
Adt Lab Record
INSTITUTE OF TECHNOLOGY
T HOVALAI - 629 302
KANYAKUMARI DISTRICT
PRACTICAL RECORD
NAME : ………………………………………………
REG.NUMBER : ………………………………………………
SUB.CODE : MC4211
DEPARTMENT OF COMPUTER APPLICATIONS
C.S.I. INSTITUTE OF TECHNOLOGY
THOVALAI - 629 302
CERTIFICATE
Certified that, this is a bonafide record work done
by ………………………………………………. Reg. No ....................................in
the MCA Computer Laboratory for ADVANCED DATABASE TECHNOLOGY
Submitted for the Anna University MCA Degree Practical Examination held
at C.S.I. INSTITUTE OF TECHNOLOGY, THOVALAI on ………………….
1 NOSQL Exercises
AIM:
To perform CRUD operations, Indexing, Sharding, Deployment in MongoDB
PROCEDURE:
1. Start MongoDB
2. Create Collection
3. Inserting document into collection
4. Querying document based on the criteria
5. Updating Document
6. Deleting Document from collection
7. Create index in MongoDB
8. Finding the indexes in a collection
9. Drop indexes in a collection
MongoDB Commands
> show dbs; // To list down all the databases
//Creating a collection user and inserting a document in it.
> db.user.insert({name:"Mala", age:22})
> show dbs
> db.dropDatabase() //To drop Database
> use test
> db.admin.insert({username:"admin",
password: "admin"})
> db.got.find().pretty()
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 2,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
> db.students.find()
"_id" : ObjectId("605ef5b7c3907340f7f6f093"),
"StudentId" : 1001,
"StudentName" : "Steve",
"age" : 30
}
{
"_id" : ObjectId("605ef5b7c3907340f7f6f094"),
"StudentId" : 1002,
"StudentName" : "Neha",
"age" : 20
}
> db.students.update({"StudentName":"Steve"},{$set:{"StudentName":"Mala"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.students.find().pretty()
{
"_id" : ObjectId("605ef5b7c3907340f7f6f093"),
"StudentId" : 1001,
"StudentName" : "Mala",
"age" : 30
}
{
"_id" : ObjectId("605ef5b7c3907340f7f6f094"),
"StudentId" : 1002,
"StudentName" : "Neha",
"age" : 20
}
> db.students.remove({"StudentId":1001})
WriteResult({ "nRemoved" : 1 })
> db.students.find().pretty()
{
"_id" : ObjectId("605ef5b7c3907340f7f6f094"),
"StudentId" : 1002,
"StudentName" : "Neha",
"age" : 20
}
> db.students.createIndex({StudentId:1})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.students.dropIndex({StudentId:1})
{ "nIndexesWas" : 2, "ok" : 1 }
>
RESULT
Thus the MongoDB CRUD operations, Indexing and Deployment have been verified and
executed successfully.
Exp. No : 1 (b) Cassandra: Table Operations, CRUD Operations,
Date : CQL Types
AIM:
To perform Table Operations, CRUD Operations, CQL Types in Cassandra
PROCEDURE:
1. Start Cassandra Server
2. Create Keyspace
3. Create table
4. Inserting records into the table
5. Create index on the table
6. Perform Read, Update, Delete Operations and Cassandra Query Language Types
Cassandra Commands
//Keyspace is a namespace of tables
CREATE KEYSPACE test
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
//Use the new keyspace
USE test;
//Create Table
CREATE TABLE user (
user_id int PRIMARY KEY,
first_name text,
last_name text
);
//Insert data:
INSERT INTO user (user_id, first_name, last_name)
VALUES (1, 'Ming', 'Li');
INSERT INTO user (user_id, first_name, last_name)
VALUES (2, 'Hong', 'Zhang');
INSERT INTO user (user_id, first_name, last_name)
VALUES (3, 'Lin', 'Li');
//Fetch data:
SELECT * FROM user;
//Next, fetch users whose last name is 'Li' by creating an index.
CREATE INDEX ON user (last_name);
SELECT * FROM user WHERE last_name = 'Li';
//Updating Records
UPDATE user
SET first_name = 'Hema' WHERE user_id=1;
//Adding a column
//Dropping a column
ALTER TABLE user
DROP age;
// Deleting Records
DELETE FROM user WHERE user_id=1;
Output:
(3 rows)
cqlsh:mca> CREATE INDEX ON user(last_name);
cqlsh:mca> SELECT * FROM user WHERE last_name = 'M';
user_id | first_name | last_name
+ +
1 | Ratha | M
3| Hema | M
(2 rows)
cqlsh:mca> UPDATE user SET first_name='Raja' WHERE user_id=1;
cqlsh:mca> SELECT * FROM user;
(3 rows)
cqlsh:mca> ALTER TABLE user ADD age int;
cqlsh:mca> ALTER TABLE user DROP age;
cqlsh:mca> DELETE ROM user WHERE user_id=1;
Bad Request: line 1:11 no viable alternative at input 'user'
cqlsh:mca> DELETE FROM user WHERE user_id=1;
cqlsh:mca>
RESULT
Thus the Table Operations, CRUD Operations and CQL types have been verified and executed
successfully in Cassandra.
Exp. No : 1 (c)
OrientDB Graph database – OrientDB Features
Date :
AIM
To perform OrientDB Graph database operations.
PROCEDURE:
1. Starting the OrientDB Console
2. Connecting to Server Instances
3. Create Vertices and Edges
4. Traverse the Graph
OrientDB Commands
Starting the OrientDB Console
In the OrientDB installation directory under bin, there is a file called console.bat for Windows
users.
Connecting to Server Instances
orientdb> CONNECT remote:localhost root my_root_password
To display the list of available Databases
orientdb> LIST DATABASES
To create a brand new local database:
orientdb> create database plocal:../databases/cars admin admin plocal
To create the first graph schema with "Person" and "Car" as 2 new Vertex types and "Owns" as an
Edge type:
orientdb> create class Person extends V
orientdb> create class Car extends V
orientdb> create class Owns extends E
To populate the database with the first Graph elements:
orientdb> create vertex Person set name = 'Luca'
orientdb> create vertex Car set name = 'Ferrari Modena'
orientdb> create edge Owns from (select from Person) to (select from Car)
Now we can traverse vertices. For example, to know the Luca's car, Traverse from Luca
vertex to the outgoing vertices following the "Owns" relationships:
orientdb> select name from ( select expand( out('Owns') ) from Person where name = 'Luca' )
Output:
Found 1 databases:
* demodb
orientdb {db=cars}> create edge Owns from (select from Person) to (select from Car)
+ + + + + +
|# |@RID |@CLASS|out |in |
+ + + + + +
|0 |#58:0|Owns |#34:0|#46:0|
+ + + + + +
Created '1' edges in 0.031000 sec(s).
orientdb {db=cars}> select name from ( select expand( out('Owns') ) from Person where name =
'Luca' )
+ + +
|# |name |
+ + +
|0 |Ferrari Modena|
+ + +
RESULT:
Thus the OrientDB Graph database operations have been verified and executed successfully.
Exp. No : 2
MySQL Database Creation, Table Creation, Query
Date :
AIM:
To perform Database Creation, Table Creation and Querying in MqSQL
PROCEDURE:
1. Start MySQL
2. Create Database
3. Create table into the Database
4. Inserting records into the table
5. Updating records from the table
6. Querying records from the table
7. Deleting records from table
8. Drop the table
9. Drop the database
MySQL Commands
CREATE DATABASE Student; // To create Database
USE Student; //To use the database Student
SHOW DATABASES; //To display all the databases
//To Create the Table
CREATE TABLE student(snum INT(4) PRIMARY KEY, sname varchar(10), major
VARCHAR(10), lev VARCHAR(2), age INT(2));
//To insert records into the table
INSERT INTO student (snum,sname,major,lev,age) values(121,'Agrawal','CSE','SR',21);
INSERT INTO student (snum,sname,major,lev,age) values(119, 'Tony ', 'CSE', 'SR',21);
INSERT INTO student (snum,sname,major,lev,age) values(122, ' Krishna ', 'CSE', 'JR',20);
mysql> CREATE TABLE student(snum INT(4) PRIMARY KEY, sname varchar(10), major VA
RCHAR(10), lev VARCHAR(2), age INT(2));
Query OK, 0 rows affected (0.08 sec)
mysql> INSERT INTO student (snum,sname,major,lev,age) values(122, ' Krishna ', '
CSE', 'JR',20);
Query OK, 1 row affected (0.11 sec)
mysql> SELECT * FROM student WHERE sname = "Tony" AND age = 21;
+ + + + + +
| snum | sname | major | lev | age |
+ + + + + +
| 119 | Tony | CSE | SR | 21 |
+ + + + + +
1 row in set (0.00 sec)
mysql> SELECT snum, sname, major FROM student ORDER BY snum DESC;
+ + + +
| snum | sname | major |
+ + + +
| 122 | Krishna | CSE |
| 121 | Agrawal | CSE |
| 119 | Tony | CSE |
+ + + +
3 rows in set (0.00 sec)
RESULT :
Thus the Database Creation, Table Creation and Querying in MqSQL has been verified and
executed successfully.
Exp. No : 3
Date : Replication – Distributed Databases
AIM:
To perform Replication of Distributed Databases.
PROCEDURE:
Backing Up a Replica Using mysqldump
Stop the replica from processing requests. You can stop replication completely on the replica
using mysqladmin:
shell>mysqladmin stop-slave
Alternatively, you can stop only the replication SQL thread to pause event execution:
shell>mysql-e'STOP SLAVE SQL_THREAD;'
1. Run mysqldump to dump your databases. You may either dump all databases or select databases
to be dumped. For example, to dump all databases:
shell>mysqldump--all-databases>fulldb.dump
2. Once the dump has completed, start replica operations again:
shell>mysqladmin start-slave
mysql>SHOWSLAVESTATUS\G
*************************** 1. row ***************************
• Slave_IO_State: Waiting for master to send event
• Master_Host: source1
• Master_User: root
• Master_Port: 3306
• Connect_Retry: 60
• Master_Log_File: mysql-bin.000004
• Read_Master_Log_Pos: 931
• Relay_Log_File: replica1-relay-bin.000056
• Relay_Log_Pos: 950
• Relay_Master_Log_File: mysql-bin.000004
• Slave_IO_Running: Yes
• Slave_SQL_Running: Yes
• Replicate_Do_DB:
• Replicate_Ignore_DB:
• Replicate_Do_Table:
• Replicate_Ignore_Table:
• Replicate_Wild_Do_Table:
• Replicate_Wild_Ignore_Table:
• Last_Errno: 0
• Last_Error:
• Skip_Counter: 0
• Exec_Master_Log_Pos: 931
• Relay_Log_Space: 1365
• Until_Condition: None
• Until_Log_File:
• Until_Log_Pos: 0
• Master_SSL_Allowed: No
• Master_SSL_CA_File:
• Master_SSL_CA_Path:
• Master_SSL_Cert:
• Master_SSL_Cipher:
• Master_SSL_Key:
• Seconds_Behind_Master: 0
• Master_SSL_Verify_Server_Cert: No
• Last_IO_Errno: 0
• Last_IO_Error:
• Last_SQL_Errno: 0
• Last_SQL_Error:
• Replicate_Ignore_Server_Ids: 0
On the source, you can check the status of connected replicas using SHOW PROCESSLIST to
examine the list of running processes. Replica connections have Binlog Dump in
the Command field:
mysql>SHOWPROCESSLIST \G;
• *************************** 4. row ***************************
• Id: 10
• User: root
• Host: replica1:58371
• db: NULL
• Command:Binlog Dump
• Time: 777
• State: Has sent all binlog to slave; waiting for binlog to be updated
• Info: NULL
Because it is the replica that drives the replication process, very little information is available in this
report.
For replicas that were started with the --report-host option and are connected to the source, the SHOW
SLAVE HOSTS statement on the source shows basic information about the replicas. The output
includes the ID of the replica server, the value of the --report-host option, the connecting port, and
source ID:
mysql>SHOWSLAVEHOSTS;
Output :
• + + + + + +
• |Server_id| Host | Port |Rpl_recovery_rank|Master_id|
• + + + + + +
• | 10 | replica1 | 3306 | 0| 1|
• + + + + + +
• 1 row in set (0.00 sec)
RESULT
Thus the Replication of Distributed Databases in MySQL has been verified and executed
successfully.
Exp. No : 4
Spatial data storage and retrieval in MySQL
Date :
AIM:
To perform Spatial data storage and retrieval in MySQL.
PROCEDURE:
1. Start MySQL
2. Create Database
3. Create table into the Database
4. Inserting spatial data
5. Retrieving records from the table
MySQL Commands
// CREATE TABLE statement to create a table with a spatial column
CREATE TABLE geotest (code int(5),descrip varchar(50), g GEOMETRY);
describe geotest;
//Point is a geometry which represents a single location in coordinate space.
ALTER TABLE geotest ADD pt_loca POINT;
ALTER TABLE geotest DROP pt_loca ;
//LineString is a Curve with linear interpolation between points.
SET @g = 'LINESTRING(0 0,1 2,2 4)';
INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
//Polygon is a planar Surface representing a multi sided geometry.
SET @g = 'POLYGON((0 0,8 0,12 9,0 9,0 0),(5 3,4 5,7 9,3 7, 2 5))';
INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
//GeometryCollection is a geometry that is a collection of one or more geometries of any class.
SET @g ='GEOMETRYCOLLECTION(POINT(3 2),LINESTRING(0 0,1 3,2 5,3 5,4 7))';
INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
//MultiPoint is a geometry collection composed of Point elements.
SET @g ='MULTIPOINT(0 0, 15 25, 45 65)';
INSERT INTO geotest VALUES (123,"Multipoint",GeomFromText(@g));
// MultiLineString is a MultiCurve geometry collection composed of LineString elements.
SET @g ='MULTILINESTRING((12 12, 22 22), (19 19, 32 18))';
INSERT INTO geotest VALUES (123,"Multistring",GeomFromText(@g));
//MultiPolygon is a MultiSurface object composed of Polygon elements.
SET @g ='MULTIPOLYGON(((0 0,11 0,12 11,0 9,0 0)),((3 5,7 4,4 7,7 7,3 5)))';
INSERT INTO geotest VALUES (123,"Multipolygon",GeomFromText(@g));
mysql> SET @g = 'POLYGON((0 0,8 0,12 9,0 9,0 0),(5 3,4 5,7 9,3 7, 2 5))';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @g ='MULTIPOLYGON(((0 0,11 0,12 11,0 9,0 0)),((3 5,7 4,4 7,7 7,3 5)))
';
Query OK, 0 rows affected (0.00 sec)
+
| code | descrip |g
|
+ + +
+
| 123 | Test Data | ☺☻ ♥ ≡? @ @
►@
|
| 123 | Test Data | NULL
|
| 123 | Test Data | ☺ ☻ ☺☺ @ @☺☻ ♣
≡? @ @ ¶@ @ ¶@ ►@ ∟@
|
| 123 | Multipoint | ☺♦ ♥ ☺☺ ☺☺ .@ 9@☺
☺ ÇF@ @P@
|
| 123 | Multistring | ☺♣ ☻ ☺☻ ☻ (@ (@ 6@ 6@☺☻
☻ 3@ 3@ @@ 2@
|
| 123 | Multipolygon | ☺♠ ☻ ☺♥ ☺ ♣ &@
(@ &@ "@ ☺♥ ☺ ♣ @ ¶@
∟@ ►@ ►@ ∟@ ∟@ ∟@ @ ¶@ |
+ + +
+
6 rows in set (0.00 sec)
RESULT
Thus the Spatial data storage and retrieval in MySQL has been verified and executed
successfully.
Exp. No : 5
Temporal data storage and retrieval in MySQL
Date :
AIM:
To perform Temporal data storage and retrieval in MySQL
PROCEDURE:
1. Start MySQL
2. Create Database
3. Create table into the Database
4. Inserting temporal data into the table
5. Retrieving records from the table
MySQL Commands
CREATE TABLE ts_test1 ( ts1 TIMESTAMP, data CHAR(30));
DESCRIBE ts_test1;
INSERT INTO ts_test1 (data) VALUES ('original_value');
SELECT * FROM ts_test1;
UPDATE ts_test1 SET data='updated_value';
SELECT * FROM ts_test1;
Enter password:
mysql> show databases;
+ +
| Database |
+ +
| information_schema |
| mysql |
| performance_schema |
| student |
| test |
+ +
5 rows in set (0.05 sec)
| 2021-03-27 20:08:41 |
+ +
1 row in set (0.00 sec)
mysql>
RESULT:
Thus the Temporal data storage and retrieval in MySQL has been verified and executed
successfully.
Exp. No : 6
Date : Object storage and retrieval in MySQL
AIM:
To perform object storage and retrieval in MySQL
PROCEDURE:
1. Start MySQL
2. Create Database
3. Create Table
4. Add JSON object column
5. Storing, Retrieving and Updating the objects
MySQL Commands
1. Create table EMP with ID and Name columns.
3. Insert 2 records to the EMP table including the JSON object values.
5. Display only the Distinct information from the JSON Object from the EMP table
6. Display the Employee Name and JSON attribute values of EMP records.
7. Display the Employee Name and JSON attribute values of EMP records of employees
coming from City "Thovalai".
SELECT empName AS "Name", empInfo->>"$.City" AS "City", empInfo->>"$.District"
8. Update JSON Object City value of EMP table where empID is 101
UPDATE EMP SET empInfo = JSON_SET(empInfo, '$.City', 'Kottar') WHERE
empID = 101;
Output:
RESULT:
Thus the object storage and retrieval in MySQL has been verified and executed successfully.
Exp. No : 7
Date : XML Databases , XML table creation, XQuery FLWOR
AIM:
To perform XML databases, XML table creation and XQuery FLWOR expression
PROCEDURE:
Step 1: Click start programs
Step 2: Select notepad
Step 3: Type the xml codings
Step 4: Save the file with extension .xml
Step 5: Run the file
Step 6: output will be displayed on the window.
Step 7: end
Program:
RESULT:
Thus the XML databases, XML table creation and XQuery FLWOR expression operations
have been verified and executed successfully.