0% found this document useful (0 votes)
4 views57 pages

DBMS

The document outlines the process of creating and managing a database using SQL commands, including Data Definition Language (DDL) and Data Manipulation Language (DML) commands. It details the creation of tables, addition of constraints, and operations such as inserting, updating, and deleting records. Additionally, it explains referential integrity and foreign key constraints in the context of relational databases.

Uploaded by

gkeerthana
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)
4 views57 pages

DBMS

The document outlines the process of creating and managing a database using SQL commands, including Data Definition Language (DDL) and Data Manipulation Language (DML) commands. It details the creation of tables, addition of constraints, and operations such as inserting, updating, and deleting records. Additionally, it explains referential integrity and foreign key constraints in the context of relational databases.

Uploaded by

gkeerthana
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
You are on page 1/ 57

EX.

NO:1 Create a database table, add constraints, insert rows, update and delete
rows using SQL DDL and DML commands.

AIM:
To create a Database table, add constraints (primary key, unique, check, Not null),
insert rows, update and delete rows using SQL DDL and DML commands.

DATA DEFINITION LANGUAGE (DDL) COMMANDS IN DBMS

DDL(DATADEFINITIONLANGUAGE)
❖ CREATE

❖ ALTER

❖ DROP

❖ TRUNCATE

❖ COMMENT

❖ RENAME

PROCEDURE

STEP1: Start

STEP2: Create the table with its essential attributes.

STEP 3: Execute different Commands and extract information from the

table.

STEP4: Stop

SQLCOMMANDS
1. COMMAND NAME: CREATE
COMMAND DESCRIPTION: CREATE command is used to create
objects in the database.
2. COMMAND NAME: DROP
COMMAND DESCRIPTION: DROP command is used to delete the object from
the database.
3. COMMAND NAME: TRUNCATE
COMMAND DESCRIPTION: TRUNCATE command is used to remove all the
records from the table

4. COMMAND NAME: ALTER


COMMAND DESCRIPTION: ALTER command is used to alter the structure of
database
5. COMMAND NAME: RENAME
COMMAND DESCRIPTION: RENAME command is used to rename the objects.

QUERY:01

Q1. Write a query to create a table employee with empno, ename, designation, and
salary.

Syntax for creating a table:

SQL:
CREATE<OBJ.TYPE><OBJ.NAME>(COLUMNNAME.1<DATATYPE>(SIZE),
COLUMNNAME.1<DATATYPE>(SIZE) ...........................................);
QUERY:01
SQL>CREATETABLEEMP(EMPNO NUMBER(4),
ENAME VARCHAR2(10),
DESIGNATIN VARCHAR2(10),
SALARY NUMBER(8,2));
Table created.
QUERY:02

Q2. Write a query to display the column name and datatype of the table employee.

Syntax for describe the table:

SQL:
DESC<TABLENAME>;
SQL>DESC EMP;

QUERY:03

Q3 .Write a query for create a from an existing table with all the fields

Syntax For Create A from An Existing Table With All Fields


SQL>CREATETABLE<TRAGETTABLENAME> SELECT*FROM
<SOURCETABLENAME>;
QUERY:03

SQL>CREATETABLEEMP1ASSELECT*FROM EMP;
Table created.

SQL>DESC EMP1;

QUERY:04

Q4. Write a query for create a from an existing table with selected fields

Syntax For Create A from An Existing Table With Selected Fields

SQL>CREATETABLE<TRAGETTABLENAME>SELECTEMPNO,ENAME
FROM<SOURCE TABLE NAME>;

QUERY:04

SQL>CREATE TABLE EMP2 AS SELECT EMPNO, ENAME FROM EMP;


Table created.

SQL>DESC EMP2;

QUERY:05

Q5 .Write a query for create a new table from an existing table without any record:

Syntax for create a new table from an existing table without any record:

SQL>CREATETABLE<TRAGETTABLENAME> ASSELECT*FROM
<SOURCETABLENAME>WHERE<FALSECONDITION>;

QUERY:05
SQL> CREATE TABLE EMP3 AS SELECT * FROM EMP
WHERE1>2;
Table created.

SQL>DESC
EMP3;

ALTER & MODIFICATION ON TABLE

QUERY:06
Q6. Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO
NUMBER(6).

Syntax for Alter & Modify on a Single Column:

SQL > ALTER <TABLE NAME> MODIFY <COLUMN


NAME><DATATYPE>(SIZE);

QUERY:06
SQL>ALTER TABLE EMP MODIFY EMPNO NUMBER(6);

Table altered.
SQL>DESC EMP;

QUERY:07
Q7. Write a Query to Alter the table employee with multiple columns
(EMPNO,ENAME.)

Syntax for alter table with multiple column:

SQL > ALTER <TABLE NAME> MODIFY <COLUMN


NAME1><DATATYPE>(SIZE),MODIFY
<COLUMNNAME2><DATATYPE> (SIZE)…..;
QUERY:07

SQL>ALTER TABLE EMP MODIFY (EMPNO NUMBER (7),


ENAMEVARCHAR2(12));
Table altered.

SQL>DESC EMP;

QUERY:08
Q8. Write a query to add a new column into employee
Syntax for add a new column:
SQL> ALTER TABLE <TABLE NAME> ADD (<COLUMN
NAME><DATATYPE><SIZE>);

QUERY:08
SQL>ALTERTABLEEMPADDQUALIFICATIONVARCHAR2(6);
Table altered.
SQL>DESC
EMP;

QUERY:09
Q9. Write a query to add multiple columns into employee
Syntax for add a new column:
SQL> ALTER TABLE <TABLE NAME> ADD (<COLUMN
NAME1><DATATYPE><SIZE>,(<COLUMN NAME2><DATA
TYPE><SIZE>,
………………………………………………………………);

QUERY:09

SQL>ALTER TABLE EMP ADD(DOB DATE,DOJ DATE);


Table altered.
SQL>DESC
EMP;

REMOVE/DROP

QUERY:10
Q10.Writeaquerytodropacolumnfromanexistingtable employee
Syntax for add a new column:
SQL>ALTERTABLE<TABLENAME>DROPCOLUMN<COLUMNNAME>;
QUERY:10

SQL>ALTER TABLE EMP DROP COLUMN DOJ;

Table altered.
SQL>DESC
EMP;
QUERY:11
Q10.Write a query to drop multiple columns from employee
Syntax for add a new column:
SQL>ALTERTABLE<TABLENAME>DROP<COLUMN
NAME1>,<COLUMNNAME2>,… ........................................... ;

QUERY:11

SQL>ALTER TABLE EMP DROP(DOB,QUALIFICATION);


Table altered.

SQL>DESC EMP;

REMOVE

QUERY:12
Q10. Write a query to rename table emp to employee.
Syntax for add a new column:
SQL>ALTERTABLERENAME<OLDNAME> TO<NEWNAME>
QUERY:12

SQL>ALTER TABLE EMP RENAME EMP TO


EMPLOYEE;
SQL>DESC EMPLOYEE;

RESULT:
Thus the program to implement DDL and DML commands was executed and
verified successfully.
1.B.

Aim:
To write a program to add the constraints to the table.

CONSTRAINTS

Constraints are part of the table definition that limits and restriction on the
value entered into its columns.

TYPES OF CONSTRAINTS:

1) Primary key
2) Check
3) Unique
4) Not null
CONSTRAINTS CAN BE CREATED IN THREE WAYS:

1) Column level constraints


2) Table level constraints
3) Using DDL statements-alter table command

OPERATION ON CONSTRAINT:
i) ENABLE
ii) DISABLE
iii) DROP

Column level constraints Using Primary key

Q13.Write a query to create primary constraints with column level


Primary key

Syntax for Column level constraints Using Primary key:


SQL:>CREATE <OBJ.TYPE><OBJ.NAME> (COLUMN NAME.1
<DATATYPE>(SIZE)<TYPEOFCONSTRAINTS>,COLUMNNAME.1<DATA
TYPE>(SIZE) ................... );

QUERY:13

SQL>CREATE TABLE EMPLOYEE(EMPNO NUMBER(4) PRIMARY


KEY,ENAME VARCHAR2(10), JOB VARCHAR2(6), SAL NUMBER(5),
DEPTNO NUMBER(7));

Table level constraint with alter command(primary key):

Q14.Write a query to create primary constraints with alter command

Syntax for Column level constraints Using Primary key:


SQL:>CREATE<OBJ.TYPE><OBJ.NAME>(COLUMNNAME.1
<DATATYPE>(SIZE),COLUMN NAME.1 <DATATYPE> (SIZE));
SQL> ALTER TABLE <TABLE NAME> ADD CONSTRAINTS <NAME OF
THECONSTRAINTS><TYPEOFTHECONSTRAINTS><COLUMNNAME>);

QUERY:14
SQL>CREATE TABLE EMPLOYEE ( EMPNO NUMBER(5),ENAME
VARCHAR2(6),JOB VARCHAR2(6),SAL NUMBER(6),DEPTNO NUMBER(6));
SQL>ALTER TABLE EMP3 ADD CONSTRAINT EMP3_EMPNO_PK
PRIMARYKEY(EMPNO);

Check constraint

Column Level Check Constraint


Q15: Write a query to create Check constraints with column level
Syntax for column level constraints using Check:
SQL:>CREATE <OBJ.TYPE><OBJ.NAME> (COLUMN NAME.1
<DATATYPE>(SIZE) CONSTRAINT <CONSTRAINTS NAME><TYPEOF
CONSTRAINTS>(CONSTRAITNSCRITERIA),COLUMNNAME2<DATATYP
E>(SIZE));

QUERY:15

SQL>CREATE TABLE EMP7 (EMPNO NUMBER(3),ENAME VARCHAR2(20),


DESIGN VARCHAR2(15), SAL NUMBER(5) CONSTRAINT
EMP7_SAL_CK CHECK (SAL>500 AND SAL<10001),DEPTNO
NUMBER(2));

Unique Constraint
Column Level Constraint
Q16: Write a query to create unique constraints with column level

Syntax for Column level constraints with unique

SQL: >CREATE <OBJ TYPE><OBJ NAME> (<COLUMN NAME 1><DATA


TYPE>(SIZE) CONSTRAINT <NAME OF CONSTRAINT><CONSTRAINT
TYPE>,(COLUMN NAME 2<DATA TYPE >(SIZE));

SQL>CREATE TABLE EMP10 ( EMPNO


NUMBER(3), ENAME VARCHAR2(20),
DESGIN VARCHAR2(15) CONSTRAINT EMP10_DESIGN_UK
UNIQUE, SAL NUMBER(5));
Not Null

Column Level Constraint


Q.17. Write a query to create Not Null constraints with column level
Syntax for Column level constraints with Not Null:
SQL:>CREATE<OBJ.TYPE><OBJ.NAME>(<COLUMNNAME.1>
<DATATYPE>(SIZE)CONSTRAINT<NAMEOFCONSTRAINTS>
<CONSTRAINTTYPE>,(COLUMNNAME2<DATATYPE>(SIZE));

QUERY:17
SQL>CREATE TABLE EMP13( EMPNO NUMBER(4), ENAME VARCHAR2(20)
CONSTRAINT EMP13_ENAME_NN NOT NULL, DESIGN VARCHAR2(20), SAL
NUMBER(3));

RESULT:
Thus the program to implement constraints was executed and verified
successfully.
1.C :

Aim:
To write a program to implement the DML commands.

DML(DATA MANIPULATION LANGUAGE)


❖ SELECT
❖ INSERT
❖ DELETE
❖ UPDATE
TCL(TRANSACTION CONTROL LANGUAGE)
❖ COMMIT
❖ ROLLBACK
❖ SAVEPOINT

PROCEDURE

STEP1: Start
STEP2: Create the table with its essential
attributes.

STEP3: Insert the record into table


STEP 4: Update the existing records into the
table
STEP5: Delete the records into the table
STEP6: use save point if any changes occur in any portion of the record to undo its
original state.
STEP 7: use rollback for completely undo the
records
STEP6: use commit for permanently save the
records.
SQLCOMMANDS
1. COMMAND NAME: INSERT
COMMAND DESCRIPTION: INSERT command is used to Insert
objects in the database.
2. COMMAND NAME: SELECT
COMMAND DESCRIPTION: SELECT command is used to SELECT the object
from the database.
3. COMMAND NAME: UPDATE
COMMAND DESCRIPTION: UPDATE command is used to
UPDATE the records from the table
4. COMMAND NAME: DELETE
COMMAND DESCRIPTION: DELETE command is used to DELETE the
Records form the table
5. COMMAND NAME: COMMIT
COMMAND DESCRIPTION: COMMIT command is used to save
the Records.
6. COMMAND NAME: ROLLBACK
COMMAND DESCRIPTION: ROLLBACK command is used to undo the
Records.
7. COMMAND NAME: SAVEPOINT
COMMAND DESCRIPTION: SAVEPOINT command is used to undo the
Records in a particular transaction.

INSERT
QUERY:01

Q1. Write a query to insert the records into employee.


Syntax for Insert Records into a table:

SQL:>INSERTINTO <TABLENAME>VALUES<VAL1,‘VAL2’,…..);

QUERY:01
INSERT A RECORD FROM AN EXISTING TABLE:
SQL>INSERT INTO EMP VALUES(101,'NAGESWARI ','LECTURER',15000);
1rowcreated.
SELECT
QUERY:02

Q2. Write a query to display the records from employee.


Syntax for select Records from the table:

SQL>SELECT*FROM<TABLENAME>;

QUERY:02
DISPLAY THE EMPTABLE:
SQL>SELECT * FROM EMP;

INSERTARECORDUSINGSUBSITUTIONMETHOD

QUERY:03

Q3. Write a query to insert the records into employee using substitution method.
Syntax for Insert Records into the table:

SQL :> INSERT INTO <TABLE NAME> VALUES< ‘&column name’,


‘&columnname2’,…..);

QUERY:03
SQL> INSERT INTO EMP VALUES
(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY');
Enter value forempno:102
Enter value for ename:
SARAVANAN

Enter value for designatin:


LECTURER

Enter value for salary:15000

old1: INSERT INTO EMP


VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new1:INSERT INTO EMP VALUES(102,'SARAVANAN','LECTURER','15000')
1rowcreat
ed.SQL>/
Enter value forempno:103
Enter value for ename:
PANNERSELVAM

Enter value for designatin: ASST.


PROF

Enter value for salary:20000

old1: INSERT INTO


EMPVALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new1:INSERT INTO EMP
VALUES(103,'PANNERSELVAM','ASST.PROF','20000')
1rowcreated.

SQL>/
Enter value for empno: 104

Enter value for ename:


CHINNI
Enter value for designatin: HOD,
PROF
Enter value for salary:45000

old1: INSERT INTO


EMPVALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY')
new1:INSERT INTO EMP VALUES(104,'CHINNI','HOD,PROF','45000')
1rowcreated.
SQL>SELECT * FROM EMP;
UPDATE

QUERY:04

Q1. Write a query to update the records from employee.

Syntax for update Records from the table:

SQL>UPDATE<<TABLENAME>SET<COLUMNANE>=<VALUE>WHERE
<COLUMNNAME=<VALUE>;

QUERY:04

SQL>UPDATE EMP SET SALARY=16000 WHERE EMPNO=101;


1rowupdated.
SQL>SELECT * FROM EMP;

UPDATE MULTIPLE COLUMNS


QUERY:05

Q5 Write a query to update multiple records from employee.

Syntax for update multiple Records from the table:

SQL>UPDATE<<TABLENAME>SET<COLUMNANE>=<VALUE>WHERE
<COLUMNNAME=<VALUE>;

QUERY:05
SQL>UPDATE EMP SET SALARY=16000, DESIGNATIN='ASST.PROF 'WHERE
EMPNO=102;
1rowupdated.
SQL>SELECT * FROM EMP;

DELETE

QUERY:06

Q5. Write a query to delete records from employee.

Syntax for delete Records from the table:

SQL>DELETE<TABLENAME>WHERE<COLUMNNAME>=<VALUE>;

QUERY:06

SQL>DELETE EMP WHERE EMPNO=103;


1rowdeleted.
SQL>SELECT * FROM EMP;

TCL(TRNSACTIONCONTROLLANGUAGE)

SAVEPOINT:
QUERY:07

Q5 Write a query to implement the savepoint.

Syntax for savepoint:

SQL>SAVEPOINT<SAVEPOINTNAME>;

QUERY:07

SQL>SAVEPOINT S1;

Savepointcreated.

SQL>SELECT * FROM EMP;


SQL>INSERT INTO EMP VALUES(105,'PARTHASAR','STUDENT',100);
1rowcreated.
SQL>SELECT * FROM EMP;
ROLLBACK

QUERY:08

Q5. Write a query to implement the Rollback.

Syntax for savepoint:

SQL>ROLLBACK<SAVEPOINTNAME>;

QUERY:08

SQL>ROLLBACK S1;
Rollbackcomplete.

SQL>SELECT * FROM EMP;

COMMIT
QUERY:09
Q5. Write a query to implement the Rollback.
Syntax for commit:

SQL>COMMIT;
QUERY:09

SQL>COMMIT;
Commitcomplete

RESULT:
Thus the program to implement the DML commands was executed and verified
successfully.
EX.2. Create a set of tables, add foreign key constraints and incorporate referential
integrity

AIM:
To create a set of tables, add foreign key constraints and incorporate referential integrity.

Referential Integrity constraints in DBMS

A referential integrity constraint is also known as foreign key constraint. A foreign key is a key
whose values are derived from the Primary key of another table.The table from which the values
are derived is known as Master or Referenced Table and the Table in which values are inserted
accordingly is known as Child or Referencing Table, In other words, we can say that the table
containing the foreign key is called the child table, and the table containing the Primary
key/candidate key is called the referenced or parent table. When we talk about the database
relational model, the candidate key can be defined as a set of attribute which can have zero or
more attributes.

The QUERY of the Master Table or Referenced table is:

1. CREATE TABLE Student (Roll int PRIMARY KEY, Name varchar(25) , Course varc
har(10) );
Here column Roll is acting as Primary Key, which will help in deriving the value of foreign key
in the child table

The QUERY of Child Table or Referencing table is:

2. CREATE TABLE Subject (Roll int references Student, SubCode int, SubName varcha
r(10) );
In the above table, column Roll is acting as Foreign Key, whose values are derived using the
Roll value of Primary key from Master table.
SQL FOREIGN KEY Constraint

The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables.

A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY
KEY in another table.

The table with the foreign key is called the child table, and the table with the primary key is
called the referenced or parent table.
CREATE TABLE Orders(
OrderIDint NOT NULL,
OrderNumberint NOT NULL,
PersonIDint,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint
on multiple columns, use the following SQL syntax:

CREATE TABLE Orders (


OrderIDint NOT NULL,
OrderNumberint NOT NULL,
PersonIDint,
PRIMARY KEY (OrderID),
CONSTRAINT FK_PersonOrder FOREIGN KEY (PersonID)
REFERENCES Persons(PersonID)
);

DROP a FOREIGN KEY Constraint

To drop a FOREIGN KEY constraint, use the following SQL:

ALTER TABLE Orders DROP FOREIGN KEY FK_PersonOrder;

Result:
Thus set of tables to add foreign key constraints and incorporate referential integrity is dine
successfully.
EX3. Query the database tables using different ‘where’ clause conditions and also
implement aggregate functions

AIM:
To write a query the database tables using different ‘where’ clause conditions and also implement
aggregate functions

CREATE TABLES CONTACT AND SUPPLIER WITH THE FOLLOWING FIELD:


CONTACTS TABLE: FIRST_NAME, LAST_NAME, ADDRESS, CONTACT NUMBER.
SUPPLIERS TABLE: SUPPLIER_ID, SUPPLIERS, STATE, SUPPLIER_NAME

MySQL: WHERE Clause


This MySQL tutorial explains how to use the MySQL WHERE clause with syntax and
examples.Description
The MySQL WHERE clause is used to filter the results from A SELECT, INSERT, UPDATE,
or DELETE statement.
Syntax
The syntax for the WHERE Clause in MySQL is:

WHERE conditions;

Parameters or Arguments
conditions
The conditions that must be met for records to be selected.

Example - With Single condition


It is difficult to explain the syntax for the MySQL WHERE clause, so let's look at some
examples.

SELECT *
FROM contacts
WHERE last_name = 'Johnson';

In this MySQL WHERE clause example, we've used the WHERE clause to filter our results from
the contacts table. The SELECT statement above would return all rows from the contacts table
where the last_name is Johnson. Because the * is used in the SELECT, all fields from
the contacts table would appear in the result set.

Example - Using AND condition

SELECT *
FROM suppliersWHERE state = 'Florida'
AND supplier_id> 1000;

This MySQL WHERE clause example uses the WHERE clause to define multiple conditions. In
this case, this SELECT statement uses the AND Condition to return all suppliers that are located
in the state of Florida and whose supplier_id is greater than 1000.

Example - Using OR condition

SELECT supplier_id
FROM suppliers
WHERE supplier_name = 'Apple'
OR supplier_name = 'Microsoft';

This MySQL WHERE clause example uses the WHERE clause to define multiple conditions,
but instead of using the AND Condition, it uses the OR Condition. In this case, this SELECT
statement would return all supplier_id values where the supplier_name is Apple or Microsoft.

Example - Combining AND & OR conditions

SELECT *
FROM suppliers
WHERE (state = 'Florida' AND supplier_name = 'IBM')
OR (supplier_id> 5000);

This MySQL WHERE clause example uses the WHERE clause to define multiple conditions,
but it combines the AND Condition and the OR Condition. This example would return
all suppliers that reside in the state of Florida and whose supplier_name is IBM as well as all
suppliers whose supplier_id is greater than 5000.
MySQL Aggregate Functions

MySQL's aggregate function is used to perform calculations on multiple values and return
the result in a single value like the average of all values, the sum of all values, and maximum
& minimum value among certain groups of values. We mostly use the aggregate functions
with SELECT statements in the data query languages.

Execute the below statement to create an employee table:

CREATE TABLE employee(


name varchar(45) NOT NULL,
occupation varchar(35) NOT NULL,
working_date date,
working_hours varchar(10)
);

Execute the below statement to insert the records into the employee table:

INSERT INTO employee VALUES


('Robin', 'Scientist', '2020-10-04', 12),
('Warner', 'Engineer', '2020-10-04', 10),
('Peter', 'Actor', '2020-10-04', 13),
('Marco', 'Doctor', '2020-10-04', 14),
('Brayden', 'Teacher', '2020-10-04', 12),
('Antonio', 'Business', '2020-10-04', 11);

Count() Function

MySQL count() function returns the total number of values in the expression. This function
produces all rows or only some rows of the table based on a specified condition, and its return
type is BIGINT. It returns zero if it does not find any matching rows. It can work with both
numeric and non-numeric data types.

mysql> SELECT COUNT(name) FROM employee;

Sum() Function

The MySQL sum() function returns the total summed (non-NULL) value of an expression. It
returns NULL if the result set does not have any rows. It works with numeric data type only.
mysql> SELECT SUM(working_hours) AS "Total working hours" FROM employee;

AVG() Function

MySQL AVG() function calculates the average of the values specified in the column. Similar
to the SUM() function, it also works with numeric data type only.

mysql> SELECT AVG(working_hours) AS "Average working hours" FROM employee;

MIN() Function

MySQL MIN() function returns the minimum (lowest) value of the specified column. It also
works with numeric data type only.

mysql> SELECT MIN(working_hours) AS Minimum_working_hours FROM employee;

MAX() Function

MySQL MAX() function returns the maximum (highest) value of the specified column. It also
works with numeric data type only.

mysql> SELECT MAX(working_hours) AS Maximum_working_hours FROM employee;

FIRST() Function

This function returns the first value of the specified column. To get the first value of the
column, we must have to use the LIMIT clause. It is because FIRST() function only supports in
MS Access.

mysql> SELECT working_date FROM employee LIMIT 1

LAST() Function

This function returns the last value of the specified column. To get the last value of the column,
we must have to use the ORDER BY and LIMIT clause. It is because the LAST() function only
supports in MS Access.

mysql> SELECT working_hours FROM employee ORDER BY name DESC LIMIT 1;


Result:
Thus the queries for the database tables using different ‘where’ clause conditions and also
implement aggregate functions
EX4: Query the database tables and explore sub queries and simple join operations.

AIM:
To write a query the database tables and explore sub queries and simple join operations.

Syntax

1. SELECT <column, ...>


2. FROM <table>
3. WHERE expression operator
4. (
5. SELECT <column,...>
6. FROM<table>
7. WHERE<condition>
8. );

Or

SELECT Col_name [, Col_name]


2. FROM table1 [,table2]
3. WHERE Col_name OPERATOR
4. (
5. SELECT Col_name[,Col_name]
6. FROM table1 [,table2]
7. [WHERE]
8. );

Example:

1. Sub Query using WHEREClause


1. SELECT * FROM student
2. WHERE course_id in (SELECT course_id
3. FROM subject
4. WHERE course_name='Oracle')

2. Sub Query using FROM Clause

1. SELECT a.course_name, b.Avg_Age


2. FROM subject a, (SELECT course_id, Avg(Age) as Avg_Age
3. FROM student GROUP BY course_id) b
4. WHERE b.course_id = a.course_id

3. Sub Query using SELECT Clause

1. SELECT course_id, course_name,


2. (
3. SELECT count (course_id) as num_of_student
4. FROM student a
5. WHERE a.course_id = b.course_id
6. GROUP BY course_id
7. )No_of_Students
8. FROM subject b

Single Row Sub Query using HAVING Clause

1. SELECT department_id, MIN(salary)


2. FROM employees
3. GROUP BY department_id
4. HAVING MIN(salary) >( SELECT MIN(salary)
5. FROM employees
6. WHERE department_id = 50);

Multiple Row Sub Query

A Multiple Row Sub Query returns a result of multiple rows to the


outer/main/parent query. It includes the following operators:

1. IN
2. ANY
3. ALL orEXISTS

Example

1. SELECT e.first_name, e.salary


2. FROM employees e
3. WHERE salary IN ( SELECT MIN(e.salary)
4. FROM employees e
5. GROUP BY e.department_id);

Multiple Column Sub Query

Multiple Column Sub Queries are queries that return multiplecolumnstothe


outerSQLquery.Ituses the IN operator for the WHERE and HAVINGclause.

1. SELECT e.department_id, e.job_id,e.salary


2. FROM employees e
3. WHERE (e.job_id,e.salary) IN ( SELECT e.job_id, e.salary
4. FROM employees e
5. WHERE e.department_id = 50) ;

JOIN IN MYSQL
SQL JOIN

A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.Let's look at a selection from the "Orders" table. Then, look at a selection from the
"Customers" table:
OrderID CustomerID OrderDate

10308 2 1996-09-18

10309 37 1996-09-19

10310 77 1996-09-20

CustomerID CustomerName ContactName Country

1 AlfredsFutterkiste Maria Anders Germany

2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico

3 Antonio Moreno Taquería Antonio Moreno Mexico

Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the
"Customers" table. The relationship between the two tables above is the "CustomerID" column.

Then, we can create the following SQL statement (that contains an INNER JOIN), that selects
records that have matching values in both tables:

QUERY
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
Result:
Thus the queries for the database tables and explore sub queries and simple join
operations is executed successfully.
EX 5: Query the database tables and explore natural, equi and outer joins

AIM:
To write a query the database tables and explore natural, equi and outer joins.

NOTE: CREATE A TABLES CLASS AND CLASS_INFO AND INSERT VALUES.

• INNER Join or EQUI Join


SELECT column-name-list
from table-name1
INNER JOIN
table-name2
WHERE table-name1.column-name = table-name2.column-name;
Inner JOIN query will be,
SELECT * from class, class_info where class.id = class_info.id;
• Natural JOIN
Natural Join is a type of Inner join which is based on column having same name and same
datatype present in both the tables to be joined.
Natural Join Syntax is,
SELECT *
from table-name1
NATURAL JOIN
table-name2;

Natural join query will be,


SELECT * from class NATURAL JOIN class_info;
• Outer JOIN
Outer Join is based on both matched and unmatched data. Outer Joins subdivide further into,

• Left Outer Join


• Right Outer Join
• Full Outer Join

• Left Outer Join


SELECT column-name-list
from table-name1
LEFT OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;
Left outer Join Syntax is,
select column-name-list
from table-name1,
table-name2
on table-name1.column-name = table-name2.column-name(+);
SELECT * FROM class LEFT OUTER JOIN class_info ON (class.id=class_info.id);
• Right Outer Join
select column-name-list
from table-name1
RIGHT OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;
select column-name-list
from table-name1,
table-name2
on table-name1.column-name(+) = table-name2.column-name;

Example of Right Outer Join


SELECT * FROM class RIGHT OUTER JOIN class_info on (class.id=class_info.id);
• Full Outer Join
The full outer join returns a result table with the matched data of two table then remaining rows
of both lefttable and then the right table.
Full Outer Join Syntax is,
select column-name-list
from table-name1
FULL OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;
Full Outer Join query will be like,
SELECT * FROM class FULL OUTER JOIN class_info on (class.id=class_info.id);

Result:
Thus the queries to perform join operation was executed successfully
Ex 6: Write user defined functions and stored procedures in SQL
Aim:
To write user defined functions and stored procedures in SQL.
Stored procedure basics

A stored procedure is a segment of declarative SQL statements stored inside the MySQL Server

• Changing the default delimiter – learn how to change the default delimiter in MySQL.
• Creating new stored procedures – show you how to create use the CREATE
PROCEDURE statement to create a new stored procedure in the database.
• Removing stored procedures – show you how to use the DROP PROCEDURE statement to drop
an existing stored procedure.
• Variables – guide on you how to use variables to hold immediate results inside stored
procedures.
• Parameters –various types of parameters used in stored procedures including IN, OUT,
and INOUT parameter.

FUNCTION
The CREATE FUNCTION statement is also used in MySQL to support loadable functions. A
loadable function can be regarded as an external stored function. Stored functions share their
namespace with loadable functions

To invoke a stored procedure,use the CALL statement.


To invoke a stored function, refer to it in an expression. The function returns a value during
expression evaluation

Procedure Example

mysql> use employee;


Database changed

User Variable

mysql> DELIMITER $$
CREATE PROCEDURE User_Variables()
-> BEGIN
-> SET @x=15;
-> SET @y=10;
-> SELECT @x,@y,@x-@y;
-> END$$
mysql> CALL User_Variables();
-> $$

Local Variable

mysql> DELIMITER $$

mysql> CREATE PROCEDURE Local_Variables()


-> BEGIN
-> DECLARE a, b, c INT;
-> SET a = 20;
-> SET b = 5;
-> SET c = a * b;
-> SELECT a, b, c;
-> END$$

mysql>CALL Local_Variables();
-> $$

Simple Procedure

mysql> select * from table1;

mysql> CREATE PROCEDURE TEST()


-> SELECT * FROM table1;

mysql> CALL TEST();

Procedure Parameter IN

mysql> DELIMITER $$
mysql> CREATE PROCEDURE my_IN (IN var1 INT)
-> BEGIN
-> SELECT * FROM table1 LIMIT var1;

-> END$$

mysql> CALL my_IN(3);


-> $$
Procedure Parameter OUT

mysql> DELIMITER $$
mysql> CREATE PROCEDURE my_proc_OUT (OUT coursecount INT)
-> BEGIN
-> SELECT COUNT(class) INTO coursecount FROM table1;
-> END$$

mysql> CALL my_proc_OUT(@coursecount)$$

mysql> SELECT @coursecount$$

Procedure Parameter INOUT

mysql> DELIMITER $$
mysql> CREATE PROCEDURE course_counts1 (IN var1 VARCHAR(10), OUT count INT)
-> BEGIN
-> SELECT COUNT(*) INTO count FROM table1 WHERE class=var1;
-> END$$

mysql> CALL course_counts1('MCA',@count)$$


mysql> SELECT @count$$
mysql> CALL course_counts1('BCA',@count)$$
mysql> SELECT @count$$

Function Example

mysql> CREATE FUNCTION hello1 (s CHAR(20))


-> RETURNS CHAR(50) DETERMINISTIC
-> RETURN CONCAT('Hello, ',s,'!');
-> $$
mysql> SELECT hello1('world');
-> $$

Example 2:
mysql>create table customer (id int, name varchar(20), age int);
\mysql>insert into customer values (101,’pater’,32), (102,’Joseph’,30), (103,’John’,28),
(105,’stephen’,45), (105,’suzi’,26), (106,’Bob’,25);
mysql> select * from customer;
mysql> DELIMITER $$
mysql> CREATE FUNCTION customer_occupation(age int)
-> RETURNS VARCHAR(20)
-> DETERMINISTIC
-> BEGIN
-> DECLARE occupation VARCHAR(20);
-> IF age>35 THEN
-> SET occupation='Scientist';
-> ELSEIF (age<=35 AND age>=30) THEN
-> SET occupation='Engineer';
-> ELSEIF age<30 THEN
-> SET occupation='Actor';
-> END IF;
-> RETURN(occupation);
-> END$$

mysql> SELECT name,age,customer_occupation(age) FROM customer ORDER BY age;


-> $$

Result:

Thus the procedures and functions are implemented successfully


Ex 7: Execute complex transactions and realize DCL and TCL commands

AIM:
To execute complex transactions and realize DCL and TCL commands.
TCL Commands in SQL

o In SQL, TCL stands for Transaction control language.


o A single unit of work in a database is formed after the consecutive execution of commands
is known as a transaction.

o There are certain commands present in SQL known as TCL commands that help the user
manage the transactions that take place in a database.

o COMMIT. ROLLBACK and SAVEPOINT are the most commonly used TCL
commands in SQL.

Now let us take a deeper dive into the TCL commands of SQL with the help of examples. All the
queries in the examples will be written using the MySQL database.

1. COMMIT

COMMIT command in SQL is used to save all the transaction-related changes permanently to the
disk. Whenever DDL commands such as INSERT, UPDATE and DELETE are used, the changes
made by these commands are permanent only after closing the current session

To create a table named t_school, we will execute the following query:

mysql> CREATE TABLE t_school(ID INT, School_Name VARCHAR(40), Number_Of_Stud


ents INT, Number_Of_Teachers INT, Number_Of_Classrooms INT, EmailID VARCHAR(40))
;
BEGIN / START TRANSACTION command is used to start the transaction.

mysql> START TRANSACTION;


mysql> INSERT INTO t_school(ID, School_Name, Number_Of_Students, Number_Of_Teache
rs, Number_Of_Classrooms, EmailID) VALUES(1, "Boys Town Public School", 1000, 80, 12, "
[email protected]"), (2, "Guru Govind Singh Public School", 800, 35, 15, "[email protected]
"), (3, "Delhi Public School", 1200, 30, 10, "[email protected]"), (4, "Ashoka Universal Schoo
l", 1110, 40, 40, "[email protected]"), (5, "Calibers English Medium School", 9000, 31, 50, "ce
[email protected]");

mysql> COMMIT;

2. SAVEPOINT

We can divide the database operations into parts. For example, we can consider all the insert related
queries that we will execute consecutively as one part of the transaction and the delete command
as the other part of the transaction. Using the SAVEPOINT command in SQL, we can save these
different parts of the same transaction using different names

SAVEPOINT savepoint_name;

3. ROLLBACK

While carrying a transaction, we must create savepoints to save different parts of the transaction.
According to the user's changing requirements, he/she can roll back the transaction to different
savepoints. Consider a scenario: We have initiated a transaction followed by the table creation
and record insertion into the table. After inserting records, we have created a savepoint INS. Then
we executed a delete query, but later we thought that mistakenly we had removed the useful record.
Therefore in such situations, we have an option of rolling back our transaction. In this case, we
have to roll back our transaction using the ROLLBACK command to the savepoint INS, which we
have created before executing the DELETE query.

Note : Use the table T_school and insert some rows then follow the given procedure:

BEGIN / START TRANSACTION command is used to start the transaction.

mysql> START TRANSACTION;


mysql> SAVEPOINT Insertion;

mysql> UPDATE t_school SET Number_Of_Students = 9050 WHERE ID = 5;


mysql> SAVEPOINT Updation;

mysql> ROLLBACK TO Insertion;

DCL

o DCL stands for Data Control Language.


o Whenever we want to control the access to the data present in SQL tables, we will use DCL
commands in SQL. Only the authorized users can access the data stored in the tables.

o Every user will have some pre-defined privileges; accordingly, the data can be accessed by
that particular user. Using the DCL commands in SQL, we can give privileges to the user
on the SQL database and tables, or we can also revoke the given privileges from the user.

o Commands covered under DCL are:

1. GRANT

Access privileges can be assigned to a user for the databases and tables using the GRANT
command.
2. REVOKE
All the access privileges which are already assigned to the user can be revoked by using the
REVOKE command.
GRANT SELECT, UPDATE ON t_school TO USER 1 , USER2;
Permission granted
REVOKE SELECT, UPDATE ON t_school FROM USER1, USER2;
Result:
Thus the Execution of complex transactions and realize DCL
and TCL commandsdone successfully.
EX 8: Write SQL Triggers for insert, delete, and update operations

in a database table.AIM:
To write SQL Triggers for insert, delete, and update operations in a database table.

Description:

A trigger is a stored program invoked automatically in response to an event such


as insert, update, or delete that occurs in the associated table. For
example, you can define atrigger that is invoked automatically before a
new row is inserted into a table.

MySQL supports triggers that are


invoked in response tothe INSERT,
UPDATE or DELETE event.

The SQL standard defines two types of triggers: row-level triggers and statement-level
triggers.

• A row-level trigger is activated for each row that is inserted, updated, or deleted.
• A statement-level trigger is executed once for each transaction
regardless of how manyrows are inserted, updated, or deleted.

MySQL supports only row-level triggers. It doesn’t support

statement-level triggers. Managing MySQL triggers

• Create triggers – describe steps of how to create a trigger in MySQL.


• Drop triggers – show you how to drop a trigger.
• Create a BEFORE INSERT trigger – show you how to create a
BEFORE INSERT triggerto maintain a summary table from another
table.
• Create an AFTER INSERT trigger – describe how to create an
AFTER INSERT triggerto insert data into a table after inserting
data into another table.
• Create a BEFORE UPDATE trigger – learn how to create a
BEFORE UPDATE triggerthat validates data before it is updated
to the table.
• Create an AFTER UPDATE trigger – show you how
to create an AFTERUPDATE trigger to log the
changes of data in a table.
• Create a BEFORE DELETE trigger – show how to create a BEFORE DELETE
trigger.
• Create an AFTER DELETE trigger – describe how to create an AFTER DELETE
trigger.

mysql> CREATE TABLE employee(id int, name varchar(20), occupation varchar(20),


working_hours int);
mysql> Insert into employee values(1,”AAA”, “Actor”, 12),
(2,”BBB”,”Teacher”,14);
mysql> select * from employee;

Before Insert Trigger


mysql> DELIMITER $$
mysql> Create Trigger before_inserthour
-> BEFORE INSERT ON employee FOR EACH ROW
-> BEGIN
-> IF NEW.working_hours<0 THEN SET NEW.working_hours=0;
-> END IF;
-> END $$
mysql> insert into employee values(4,"DDD","Nurse",-12);
-> $$
mysql> select * from employee;
-> $$
mysql> show triggers;
-> $$

After Insert Trigger


mysql> create table emp_details1(id int,name
varchar(25),occupation
varchar(25),working_hoursint,Lastinserted
Time);

mysql> DELIMITER $$
mysql> Create Trigger after_insert_details2
-> AFTER INSERT ON employee FOR EACH ROW
-> BEGIN
-> INSERT INTO emp_details1
VALUES(NEW.id,NEW.name,NEW.occupation,NEW.working_hours,C
URTIME());
-> END$$

mysql> INSERT into employee values(8,'MMMM','Doctor',23);


-> $$
mysql> select * from employee;
-> $$
mysql> select * from emp_details1;
-> $$
Before Update Trigger
mysql> DELIMITER $$
mysql> CREATE TRIGGER before_update2
-> BEFORE UPDATE ON employee FOR EACH ROW
-> BEGIN
-> DECLARE error_msgVARCHAR(200);
-> SET error_msg=('The working hours cannot be greater than 30');
-> IF new.working_hours>30 THEN
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT=error_msg;
-> END IF;
-> END $$
mysql> update employee set working_hours=32 where id=3;
-> $$

After Update Trigger


mysql> create table student(id int, name varchar(20), class int);
mysql> insert into student values(101,'AAA',5),(102,'BBB',8),(103,'CCC',4);
mysql> select * from student;

mysql> create table studentlog(user longtext,desclongtext);


mysql> select * fromstudentlog;

mysql> CREATE TRIGGER after_updatestu1


-> AFTER UPDATE ON student FOR EACH ROW
-> BEGIN
-> INSERT into studentlog
VALUES(user(),CONCAT('update',OLD.name,'Prev:',OLD.class,'Pres:',NEW.class));
-> END$$
mysql> UPDATE student SET class = class + 1;
-> $$
mysql> select * from student;
-> $$

mysql> select * from studentlog;


-> $$
Before delete trigger
mysql> select * from employee;
-> $$
mysql> create table delemp1(id int PRIMARY KEY AUTO_INCREMENT, name varchar(30),
occupation varchar(20), deleted_time TIMESTAMP DEFAULT NOW());
mysql> CREATE TRIGGER before_delete1
-> BEFORE DELETE ON employee FOR EACH ROW
-> BEGIN
-> INSERT INTO delemp1(name,occupation) VALUES(OLD.name,OLD.occupation);
-> END$$
mysql> delete from employee where id=2;
-> $$
mysql> select * from employee;

-> $$
mysql> select * from delemp1;
-> $$

After Delete Trigger


mysql> create table empsalary(empid int, amount int);
-> $$
mysql> insert into empsalary values(101,5000),(102,4000),(103,20000),(104,8000);
-> $$
mysql> select * from empsalary;
-> $$
mysql> create table totalsalary(total_budgetint);
-> $$
mysql> insert into totalsalary(total_budget)
-> SELECT SUM(amount) from empsalary;
-> $$
mysql> select * from totalsalary;
-> $$
mysql> DELIMITER $$
mysql> CREATE TRIGGER after_delete
-> AFTER DELETE ON empsalary FOR EACH ROW
-> BEGIN
-> UPDATE totalsalary SET total_budget=total_budget-OLD.amount;
-> END $$
mysql> delete from empsalary where empid=103;
-> $$
mysql> select * from empsalary;
-> $$
mysql> select * from totalsalary;

-> $$
mysql> drop trigger after_delete;
-> $$
mysql> show triggers;
-> $$
Result:
Thus the database triggers has been implemented and executed successfully.
EX 9: Create View and index for database tables with a large number of records

AIM:
To create View and index for database tables with a large number of records.

Creating Views

Database views are created using the CREATE VIEW statement. Views can be
created from a single table, multiple tables or anotherview.
To create a view, a user must have the appropriate system privilege
according to the specific implementation.

The basic CREATE VIEW syntax is as follows −

CREATE VIEW view_name AS SELECT column1, column2...

Example :Consider the CUSTOMERS table having the following records −

| ID| NAME | AGE|ADDRESS |SALARY |

| 1|Ramesh | 32 |Ahmedabad| 2000.00|


| 2|Khilan | 25|Delhi | 1500.00|
| 3|kaushik | 23|Kota | 2000.00|

Sql> create view customers_view as select name, age from customers;


Sql> select * from customers_view;

Updating a View

SQL > UPDATE CUSTOMERS_VIEW SET AGE = 35 WHERE name = 'Ramesh';

This would ultimately update the base table CUSTOMERS and the same would reflect inthe
view itself.

Dropping Views

Obviously, where you have a view, you need a way to drop the view if it is no longer needed.
The syntax is very simple and is given below−

drop view view_name;


drop view customers_view;

CREATE INDEX Syntax

Creates an index on a table. Duplicate values are allowed:

CREATE INDEX index_name


ON table_name (column1, column2, ...);
CREATE UNIQUE INDEX Syntax

Creates a unique index on a table. Duplicate values are not allowed:

CREATE UNIQUE INDEX index_name ON table_name (column1, column2, ...);


CREATE INDEX Example

The SQL statement below creates an index named "idx_lastname" on the "LastName" column in
the "Persons" table:

CREATE INDEX idx_lastname


ON Persons (LastName);

If you want to create an index on a combination of columns, you can list the column names
within the parentheses, separated by commas:

CREATE INDEX idx_pname ON Persons (LastName, FirstName);


Query executed successfully.
mysql> CREATE TABLE t_index(col1 int primary key, col2 int not null, col3 int not null, col
4 varchar(20), index (col2,col3) );
mysql> CREATE INDEX ind_1 ON t_index(col4);
mysql> SELECT studentid, firstname, lastname FROM student WHERE class = 'CS';

Drop index:

ALTER TABLE table_name DROP INDEX index_name;


RESULT:

Thus the commands to create View and index for database tables with a large number of records
executed successfully.
EX 10: Create an XML database and validate it using XML schema

Aim:
To create an XML database and validate it using XML schema.
XML Schema
An XML Schema describes the structure of an XML document, just like a DTD.
An XML document with correct syntax is called "Well Formed".
An XML document validated against an XML Schema is both "Well Formed" and "Valid".
XML Schema is an XML-based alternative to DTD:
A Simple XML Document
Look at this simple XML document called "note.xml":
<?xml version="1.0"?>
<note>
<to>To</to>
<from>JanANI</from>
<heading>Reminder</heading>
<body>Don't forget APPOINTMENT this weekend!</body>
</note>
An XML Schema
The following example is an XML Schema file called "note.xsd" that defines the elements of the
XML document above ("note.xml"):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The Schema above is interpreted like this:

• <xs:element name="note"> defines the element called "note"


• <xs:complexType> the "note" element is a complex type
• <xs:sequence> the complex type is a sequence of elements
• <xs:element name="to" type="xs:string"> the element "to" is of type
string (text)
• <xs:element name="from" type="xs:string"> the element "from" is of
type string
• <xs:element name="heading" type="xs:string"> the element "heading"
is of type string
• <xs:element name="body" type="xs:string"> the element "body" is of
type string
RESULT:

Thus the creation of an XML database and validate it using XML


schema is successfully executed
EX 11:
Create Document, column and graph based data using
NOSQL database tools
Aim:

To create Document, column and graph based data using NOSQL


database tools.

Document databases expand on the basic idea of key-value stores where


“documents” are more complex, in that they contain data and each
document is assigned a unique key, which is used to retrieve the document.
These are designed for storing, retrieving, and managing document-
oriented information, often stored as JSON. Since the Document database
can inspect the document contents, the database can perform some
additional retrieval processing
• Access Create a new document

{
"accounts": [
{
"balance": "1000",
"id": "81def5e2-84f4-4885-a920-1c14d2be3c20",
"type": "Checking"
}
],
"email": "[email protected]",
"id": "0d2b2319-9c0b-4ecb-8953-98687f6a99ce",
"name": "Bob"
}
Expected output
{
"documentId": "137d8609-87f6-4cb7-9506-e52f338e79e9"
}

Access Get a document

• Fill Header X-Cassandra-Token with <your_token>


• For namespace-id use nosql1
• For collection-id use users
• For document-id use Bob's documentId (e.g. 137d8609-87f6-4cb7-9506-
e52f338e79e9 in the above sample output)
• Click the Execute button

Expected output

{
"documentId": "137d8609-87f6-4cb7-9506-e52f338e79e9",
"data": {
"accounts": [
{
"balance": "1000",
"id": "81def5e2-84f4-4885-a920-1c14d2be3c20",
"type": "Checking"
}
],
"email": "[email protected]",
"id": "0d2b2319-9c0b-4ecb-8953-98687f6a99ce",
"name": "Bob"
}
}
Graph data:
Graph databases store their data using a graph metaphor to exploit the relationships between
data. Nodes in the graph represent data items, and edges represent the relationships between
the data items. Graph databases are designed for highly complex and connected data, which
outpaces the relationship and JOIN capabilities of an RDBMS. Graph databases are often
exceptionally good at finding commonalities and anomalies among large data sets. Examples of
Graph databases include DataStax Graph, Neo4J, JanusGraph, and Amazon Neptune
Result:
Thus the program to create Document, column and graph based data using
NOSQL database tools

You might also like