Ddbfile

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

DISTRIBUTED DATABASES

EXPERIMENT FILE
(CDCSC18)

RISHABH
(2020UCD2144)
Index
Serial Experiment
no.
1 a) Introduction to database management systems, oracle concepts and how to
create a table.
b) How to insert data in a table using insert and display the records in a table.

2 a) Update and Delete records of a table and modify the structure of a table using
alter and drop command.
b) Study of character functions for manipulation of data items.

3 Perform join operations between various tables.

4 Applying constraints using two tables.

5 Implementation FTP Client

6 Implementation of Name Server

7 Implementation of chat server

8 Performing horizontal fragmentation and comparing performance.

9 Performing vertical fragmentation and comparing performance.


EXPERIMENT 1
AIM :- a) Introduction to database management systems, oracle concepts
and how to create a table.

THEORY :-

Database management system (DBMS) is a software application that allows users to efficiently
manage and organize large amounts of data. The system enables users to store, retrieve, update,
and delete data in a secure and controlled manner.
A database is a collection of related data that is organized and stored in a way that enables
efficient access and retrieval. A DBMS provides a way to create, modify, and maintain databases,
as well as manage the users who access them.
Some common features of a DBMS include data integrity, security, backup and recovery,
concurrency control, and data access control. These features help to ensure that data is consistent
and accurate, and that users are able to access and modify the data in a controlled and secure
manner.
There are many different types of DBMSs, including relational, object-oriented, and NoSQL
databases. Relational databases are the most common type, and they organize data into tables
with predefined relationships between them. Object-oriented databases store data as objects, and
NoSQL databases are designed for handling unstructured or semi-structured data.
Overall, a DBMS is an essential tool for managing large amounts of data efficiently and securely,
and it is used in a wide range of industries and applications, from finance and healthcare to
e-commerce and social media.

Oracle is a leading provider of database management systems and enterprise software solutions.
It offers a wide range of products and services for managing data and applications, including
database management systems, application development tools, and cloud services.

Here are some basic concepts related to Oracle:

Oracle Database: Oracle Database is a relational database management system (RDBMS) that
provides a scalable, high-performance platform for storing, retrieving, and managing data. It uses
SQL (Structured Query Language) for managing data, and it can run on a variety of platforms,
including Windows, Linux, and UNIX.
Oracle SQL: SQL is the primary language used by Oracle Database for managing data. It is a
powerful and flexible language that allows users to retrieve, update, and manipulate data stored in
the database.
PL/SQL: PL/SQL is a procedural language that extends SQL to provide programming capabilities
within the Oracle Database. It allows users to create stored procedures, functions, and triggers,
which can be used to automate tasks and improve performance.
Oracle Cloud: Oracle Cloud is a suite of cloud services provided by Oracle, including
Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service
(SaaS). It provides a range of tools and services for developing, deploying, and managing
applications and data in the cloud.
Oracle Applications: Oracle Applications are a suite of enterprise software solutions provided by
Oracle for managing various business functions, such as finance, supply chain management, and
human resources. These applications are designed to integrate with Oracle Database and other
Oracle products to provide a comprehensive solution for managing business operations.
Oracle Fusion Middleware: Oracle Fusion Middleware is a suite of software products that provide
a platform for building and deploying enterprise applications. It includes tools for application
development, integration, and management, and it is designed to work with Oracle Database and
other Oracle products.

To create a table in SQL, you can use the CREATE TABLE statement, which is used to define the
structure and columns of a table. Here is a basic syntax for creating a table:

CREATE TABLE table_name (


column1 datatype constraint,
column2 datatype constraint,
...
column_n datatype constraint
);

● CREATE TABLE is the SQL statement used to create a table.


● table_name is the name of the table you want to create.
● column1, column2, and column_n are the names of the columns you want to create in
the table.
● datatype is the data type of the column. For example, VARCHAR for text, INT for integer,
and DATE for date/time values.
● constraint is an optional constraint that can be applied to the column, such as PRIMARY
KEY or NOT NULL.

Let us consider an example of creating a simple table called employees with columns for employee
ID, name, age, and salary.

CODE :-
AIM :- b) How to insert data in table using insert and display the records
in a table.

THEORY :-

To insert data into a table using the INSERT statement, follow these steps:
● Write a SQL statement using the INSERT INTO command to specify the table name and
column names for which you want to insert data.
● Specify the values for each column in the VALUES keyword. The order of the values should
match the order of the column names specified in the previous step.
● Execute the SQL statement to insert the data into the table.

Let us try to insert some records in the employee table.

CODE :-

OUTPUT :-
EXPERIMENT 2
AIM :- a) Update and Delete records of a table and modifying structure of
a table using alter and drop command.

THEORY :-
To update or delete records from a table, you can use the UPDATE and DELETE statements,
respectively.
● UPDATE statement: The UPDATE statement is used to modify one or more rows in a
table.
● DELETE statement: The DELETE statement is used to remove one or more rows from a
table.

To modify the structure of a table, you can use the ALTER TABLE statement.
● ALTER TABLE statement: The ALTER TABLE statement is used to add, modify, or delete
columns in a table, as well as to modify the table's constraints.
● To drop an entire table, you can use the DROP TABLE statement.

Let us use modify, delete, alter and drop in the employee table.

CODE :-

RESULT :-
AIM :- b) Study of character functions for manipulation of data items.

THEORY :-
In SQL, character functions are used to manipulate and modify character strings.
● UPPER(): This function converts all characters in a string to uppercase.
● LOWER(): This function converts all characters in a string to lowercase.
● SUBSTR(): This function extracts a substring from a string.
● LENGTH(): This function returns the length of a string.
● TRIM(): This function removes specific characters from the beginning and/or end of a
string.
● CONCAT(): This function concatenates two or more strings.
● INSTR(): This function returns the position of a substring within a string.
● REPLACE(): This function replaces all occurrences of a substring with a new substring.

CODE :-
RESULT :-
EXPERIMENT 3
AIM :- Perform join operations between various tables.

THEORY :-

There are several types of join operations in SQL, including:


● INNER JOIN: Returns only the rows that have matching values in both tables.
● LEFT JOIN: Returns all the rows from the left table and matching rows from the right table,
and fills in NULL values for non-matching rows in the right table.
● RIGHT JOIN: Returns all the rows from the right table and matching rows from the left
table, and fills in NULL values for non-matching rows in the left table.
● FULL OUTER JOIN: Returns all the rows from both tables, and fills in NULL values for
non-matching rows on either side.

Suppose we have two tables, "customers" and "orders", with the following data:

customers table: orders table:


id | name | email id | customer_id | product
---+---------+---------------- ---+------------+--------
1 | Alice | [email protected] 1 |1 | Widget
2 | Bob | [email protected] 2 |2 | Gadget
3 | Charlie | [email protected] 3 |1 | Gizmo
4 |3 | Gadget

CODE :-

a) INNER JOIN
SELECT orders.id, customers.name, customers.email, orders.product
FROM orders
INNER JOIN customers
ON orders.customer_id = customers.id;

b) LEFT JOIN
SELECT customers.name, orders.product
FROM customers
LEFT JOIN orders
ON customers.id = orders.customer_id;

c) RIGHT JOIN
SELECT customers.name, orders.product
FROM customers
RIGHT JOIN orders
ON customers.id = orders.customer_id;

d) FULL OUTER JOIN JOIN


SELECT customers.name, orders.product
FROM customers
FULL OUTER JOIN orders
ON customers.id = orders.customer_id;

RESULT :-
id | name | email | product
---+---------+---------------------+--------
1 | Alice | [email protected] | Widget
2 | Bob | [email protected] | Gadget
3 | Alice | [email protected] | Gizmo
4 | Charlie | [email protected] | Gadget

name | product
------- + --------
Alice | Widget
Alice | Gizmo
Bob | Gadget
Charlie | Gadget
David | NULL

name | product
------- + --------
Alice | Widget
Alice | Gizmo
Bob | Gadget
NULL | Widget
Charlie | Gadget
name | product
------- + --------
Alice | Widget
Alice | Gizmo
Bob | Gadget
David | NULL
NULL | Widget
Charlie | Gadget
EXPERIMENT 4
AIM :- Applying constraints using two tables.

THEORY :-
Constraints are classed as either:
1. Table constraints These may reference one or more columns and are defined separately from
the definitions of the columns in the table.
2. Column constraints These reference a single column and are defined within the specification for
the owning column.

Constraint types :- You may define the following constraint type


1. Primary key
2. Foreign key
3. Unique
4. Null /Not null
5. Check

Unique constraint: The Unique column constraint permits multiple entries of NULL
into a column. These NULL values are clubbed at the top the column in order in which
they were entered into the table. This is the essential difference between the Primary Key
and Unique Constraints when applied to table column(s).

The CHECK Constraint: Business rule validations can be applied to a table column by
using CHECK constraint. It must be specified as a logical expression that evaluates either
to TRUE or FALSE

CODE :-
a) Create the a table client_master with the following fields:
clientno, name, address, city, pincode, state, bal_due.
Consider the appropriate data type and size for the columns. In addition, define
clientno as the primary key column.

CREATE TABLE client_master (


clientno INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
address VARCHAR(100) NOT NULL,
city VARCHAR(50) NOT NULL,
pincode VARCHAR(10) NOT NULL,
state VARCHAR(50) NOT NULL,
bal_due DECIMAL(10, 2) DEFAULT 0.00
);

b) Create the a table product_master with the following fields:


Productno, Description, Qty_on_hand, Sell_price, Cost_price.
Consider the appropriate data type and size for the columns. In addition, define
Productno as the primary key column and check data values being inserted into the
column Productno must start with the capital letter ‘P’

CREATE TABLE product_master (


Productno VARCHAR(10) PRIMARY KEY CHECK (Productno LIKE 'P%'),
Description VARCHAR(100) NOT NULL,
Qty_on_hand INT NOT NULL,
Sell_price DECIMAL(10, 2) NOT NULL,
Cost_price DECIMAL(10, 2) NOT NULL
);

c) Create the a table salesman_master with the following fields: Sno, S_name, Address,
city, Pincode, State, Sal_amt, Tgt_to_get Consider the appropriate data type and size
for the columns. In addition, define Sno as the primary key column

CREATE TABLE salesman_master (


Sno INT PRIMARY KEY,
S_name VARCHAR(50) NOT NULL,
Address VARCHAR(100) NOT NULL,
city VARCHAR(50) NOT NULL,
Pincode VARCHAR(10) NOT NULL,
State VARCHAR(50) NOT NULL,
Sal_amt DECIMAL(10, 2) NOT NULL,
Tgt_to_get DECIMAL(10, 2) NOT NULL
);

d) Create a table sales_order with the following fields: Orderno, clientno, orderdate,
delyaddr, sno, delydate. Consider the appropriate data type and size for the columns.
In addition, define Orderno as the primary key column and define its clientno column
as a foreign key, which references the client_master table & sno column as a foreign
key, which references the salesman_master table

CREATE TABLE sales_order (


Orderno INT PRIMARY KEY,
clientno INT,
orderdate DATE NOT NULL,
delyaddr VARCHAR(100) NOT NULL,
sno INT,
delydate DATE NOT NULL,
FOREIGN KEY (clientno) REFERENCES client_master(clientno),
FOREIGN KEY (sno) REFERENCES salesman_master(Sno)
);

e) Create the a table sales_order_details with the following fields:


Orderno, Productno, qtyordered
Consider the appropriate data type and size for the columns. In addition, define its
Orderno column as a foreign key, which references the sales_order table &
Productno column as a foreign key, which references the product_master table.

CREATE TABLE sales_order_details (


Orderno INT,
Productno VARCHAR(10),
qtyordered INT NOT NULL,
PRIMARY KEY (Orderno, Productno),
FOREIGN KEY (Orderno) REFERENCES sales_order(Orderno),
FOREIGN KEY (Productno) REFERENCES product_master(Productno)
);
EXPERIMENT 5
AIM :- Implementation FTP Client

THEORY :-

(FTP) is a standard network protocol used to transfer computer files from one host to another host
over a TCP-based network, such as the internet.FTP is built on client-server architecture and used
separate control and data connections between the client and the server. FTP users may
authenticate themselves using a clear-text sing-in-protocol, normally in the form of a username and
password, but can connect anonymously if the server is configured to allow it. For secure
transmission that protects the username and password and encrypts the content, FTP is often
secured with SSL/TLS. SSH File Transfer Protocol is sometimes also used instead, but is
technologically different.
The first FTP client applications were command line applications developed before operating
systems had graphical user interfaces, and are still shipped with most Windows, UNIX, and Linux
operating systems. Many FTP clients and automation utilities have since been developed for
desktops, servers, mobile devices, and hardware and FTP has been incorporated into productivity
applications, such as Web page editors.

CODE :-
FTP Client :-

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
class One extends JFrame implements ActionListener
{
/* ctrl space */
public JButton b,b1;
public JLabel l;
public JLabel l1,lmsg1,lmsg2;
One()
{
b=new JButton("Upload");
l=new JLabel("Uplaod a file : ");
lmsg1=new JLabel("");
b1=new JButton("Download");
l1=new JLabel("Downlaod a file");
lmsg2=new JLabel("");
setLayout(new GridLayout(2,3,10,10));
add(l);add(b);add(lmsg1);add(l1);add(b1);add(lmsg2);
b.addActionListener(this);
b1.addActionListener(this);
setVisible(true);
setSize(600,500);
}
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
try {
/* String s=e.getActionCommand();
if(s.equals("Upload"))*/
if (b.getModel().isArmed())
{
Socket s=new Socket("localhost",1010);
System.out.println("Client connected to server");
JFileChooser j=new JFileChooser();
int val;
val=j.showOpenDialog(One.this);
String filename=j.getSelectedFile().getName();
String path=j.getSelectedFile().getPath();
PrintStream out=new PrintStream(s.getOutputStream());
out.println("Upload");
out.println(filename);
FileInputStream fis=new FileInputStream(path);
int n=fis.read();
while (n!=-1)
{
out.print((char)n);n=fis.read();
}
fis.close(); out.close();lmsg1.setText(filename+"is uploaded");
//s.close();
repaint();
}
if (b1.getModel().isArmed())
{
Socket s=new Socket("localhost",1010);
System.out.println("Client connected to server");
String remoteadd=s.getRemoteSocketAddress().toString();
System.out.println(remoteadd);
JFileChooser j1=new JFileChooser(remoteadd);
int val;
val=j1.showOpenDialog(One.this);
String filename=j1.getSelectedFile().getName();
String filepath=j1.getSelectedFile().getPath();
System.out.println("File name:"+filename);
PrintStream out=new PrintStream(s.getOutputStream());
out.println("Download");
out.println(filepath);
FileOutputStream fout=new FileOutputStream(filename);
DataInputStream fromserver=new DataInputStream(s.getInputStream());
int ch;
while ((ch=fromserver.read())!=-1)
{
fout.write((char) ch);
}
fout.close();//s.close();
lmsg2.setText(filename+"is downlaoded");
repaint();
}
}
catch (Exception ee)
{
// TODO: handle exception
System.out.println(ee);
}
}
}
public class FTPClient
{
public static void main(String[] args)
{
new One();
}
}

FTP Server :-

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class FTPServer {
public static void main(String[] args)
{
try {
while (true)
{
ServerSocket ss=new ServerSocket(1010);
Socket sl=ss.accept();
System.out.println("Server scoket is created....");
System.out.println(" test1");
DataInputStream fromserver=new DataInputStream(sl.getInputStream());
System.out.println(" test2");
String option=fromserver.readLine();
if (option.equalsIgnoreCase("upload"))
{
System.out.println("upload test");
String filefromclient=fromserver.readLine();
File clientfile=new File(filefromclient);
FileOutputStream fout=new FileOutputStream(clientfile);
int ch;
while ((ch=fromserver.read())!=-1)
{
fout.write((char)ch);
}
fout.close();
}
if (option.equalsIgnoreCase("download"))
{
System.out.println("download test");
String filefromclient=fromserver.readLine();
File clientfile=new File(filefromclient);
FileInputStream fis=new FileInputStream(clientfile);
PrintStream out=new PrintStream(sl.getOutputStream());
int n=fis.read();
while (n!=-1)
{
out.print((char)n);
n=fis.read();
}
fis.close();
out.close();
} //while
}
}
catch (Exception e)
{
System.out.println(e);
// TODO: handle exception
}
}
}

RESULT :-
EXPERIMENT 6
AIM :- Implementation of Name Server

THEORY :-
Name server is a client / server network communication protocol. Name server clients
send request to the server while name servers send response to the client. Client request contain a
name which is converted into in IP address known as a forward name server lookups while
requests containing an IP address which is converted into a name known as reverse name server
lookups.
Name server implements a distributed database to store the name of all the hosts available on the
internet. If a client like a web browser sends a request containing a hostname, then a piece of
software such as name server resolver sends a request to the name server to obtain the IP
address of a hostname. If name server does not contain the IP address associated with a
hostname then it forwards the request to another name server. It IP address has arrived at the
resolver, which in turn completes the request over the internet protocol.

CODE :-
import java.net.*;
import java.io.*;
import java.util.*;
public class DNS
{
public static void main(String[] args)
{
int n;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
do
{
System.out.println("\n Menu: \n 1. DNS 2. Reverse DNS 3. Exit \n");
System.out.println("\n Enter your choice");
n = Integer.parseInt(System.console().readLine());
if(n==1)
{
try
{
System.out.println("\n Enter Host Name ");
String hname=in.readLine();
InetAddress address;
address = InetAddress.getByName(hname);
System.out.println("Host Name: " + address.getHostName());
System.out.println("IP: " + address.getHostAddress());
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
if(n==2)
{
try
{
System.out.println("\n Enter IP address");
String ipstr = in.readLine();
InetAddress ia = InetAddress.getByName(ipstr);
System.out.println("IP: "+ipstr);
System.out.println("Host Name: " +ia.getHostName());
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}while(!(n==3));
}}

RESULT :-
EXPERIMENT 7
AIM :- Implementation of chat server

THEORY :-
A client / server program into a fully functioning chat client / server. A simple server
that will accept a single client connection and display everything the client says on the screen. If
the client user’s types “OK” the client and the server will both quit. A server as before, but this time
it will remain open for additional connection once a client has quit. The server can handle at most
one connection at a time. A server as before but his time it can handle multiple clients
simultaneously. The output from all connected clients will appear on the server’s screen. A server
as before, but his time it sends all text received from any of the connected clients to all clients. This
means that the server has to receive and send the client has to send as well as receive.

CODE :-
CCLogin.java :-

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridLayout;
public class CCLogin implements ActionListener
{
JFrame frame1; JTextField tf,tf1; JButton button;
JLabel heading; JLabel label,label1;
public static void main(String[] paramArrayOfString)
{
new CCLogin();
}
public CCLogin()
{
this.frame1 = new JFrame("Login Page");
this.tf = new JTextField(10);
this.button = new JButton("Login");
this.heading = new JLabel("Chat Server");
this.heading.setFont(new Font("Impact", 1, 40));
this.label = new JLabel("Enter you Login Name");
this.label.setFont(new Font("Serif", 0, 24));
JPanel localJPanel = new JPanel();
this.button.addActionListener(this);
localJPanel.add(this.heading); localJPanel.add(this.label);
localJPanel.add(this.tf);
localJPanel.add(this.button);
this.heading.setBounds(30, 20, 280, 50);
this.label.setBounds(20, 100, 250, 60);
this.tf.setBounds(50, 150, 150, 30);
this.button.setBounds(70, 190, 90, 30);
this.frame1.add(localJPanel);
localJPanel.setLayout(null);
this.frame1.setSize(300,300);
this.frame1.setVisible(true);
this.frame1.setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent paramActionEvent)
{
String str = "";
try
{
str = this.tf.getText();
this.frame1.dispose();
Client1 c1= new Client1(str);
c1.main(null);
}
catch(Exception localIOException)
{
}
}
}

Chat MultiServer :-

import java.net.*;
import java.io.*;
class A implements Runnable
{
Thread t;
Socket s;
A(Socket x)
{
s=x;
t=new Thread(this);
t.start();
}
public void run()
{
try
{
/* Reading data from client */
InputStream is=s.getInputStream();
byte data[]=new byte[50];
is.read(data);
String mfc=new String(data);
mfc=mfc.trim();
System.out.println(mfc);
/* Sending message to the server */
//System.out.println("Hi"+name+"u can start chating");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String n=br.readLine();
OutputStream os=s.getOutputStream();
os.write(n.getBytes());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class ChatMultiServer
{
static int c=0;
public static void main(String args[]) throws Exception
{
System.out.println("ServerSocket is creating");
ServerSocket ss=new ServerSocket(1010);
System.out.println("ServerSocket is created");
System.out.println("waiting for the client from the client");
while(true)
{
Socket s=ss.accept();
new A(s);
}
}
}

Client1.java :-

import java.net.*;
import java.io.*;
class Client1
{
static String name="";
public Client1(String n)
{
name=n;
}
public static void main(String args[]) throws Exception
{
System.out.println("connecting to server");
System.out.println("client1 connected to server");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
/* Sending message to the server */
System.out.println("Hi\t"+name+" u can start chating");
while(true)
{
Socket s=new Socket("localhost",1010);
String n=br.readLine();
OutputStream os=s.getOutputStream();
os.write(n.getBytes());
/* Reading data from client */
InputStream is=s.getInputStream();
byte data[]=new byte[50];
is.read(data);
String mfc=new String(data);
mfc=mfc.trim();
System.out.println(mfc);
}
}
}

RESULT :-
EXPERIMENT 8
AIM :- Performing horizontal fragmentation and comparing performance.

THEORY :-
We will create a sample table and then fragment it horizontally based on a specific criteria. We will
then compare the performance of queries executed on the original table with the same queries
executed on the horizontally fragmented table.

we create a sample table called customers and insert some data into it. We then horizontally
fragment the table into two fragments based on the age column. The customers_under_40 table
contains all rows where age is less than 40, while the customers_over_40 table contains all rows
where age is greater than or equal to 40.

Next, we can execute some sample queries on both the original table and the horizontally
fragmented tables to compare performance.

CODE :-

CREATE TABLE customers1 (


id INT PRIMARY KEY,
name VARCHAR(50),
city VARCHAR(50),
country VARCHAR(50),
age INT
);

-- insert sample data


INSERT INTO customers1 VALUES
(1, 'John Smith', 'New York', 'USA', 35),
(2, 'Jane Doe', 'San Francisco', 'USA', 28),
(3, 'Bob Johnson', 'Toronto', 'Canada', 42),
(4, 'Sara Lee', 'Sydney', 'Australia', 25),
(5, 'Juan Perez', 'Mexico City', 'Mexico', 30),
(6, 'Hans Schmidt', 'Berlin', 'Germany', 50);

-- horizontally fragment table based on age


CREATE TABLE customers1_under_40 AS
SELECT * FROM customers1 WHERE age < 40;

CREATE TABLE customers1_over_40 AS


SELECT * FROM customers1 WHERE age >= 40;

RESULT :-
EXPERIMENT 9
AIM :- Performing vertical fragmentation and comparing performance.

THEORY :-
We will create a sample table and then fragment it vertically based on a specific criteria. We will
then compare the performance of queries executed on the original table with the same queries
executed on the vertically fragmented table.
We create a sample table called orders and insert some data into it. We then vertically fragment
the table into two tables based on columns. The orders_info table contains the order

CODE :-
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE,
product_id INT,
quantity INT,
price DECIMAL(10,2)
);

-- insert sample data


INSERT INTO orders VALUES
(1, 2, '2023-04-22', 10, 5, 10.99),
(2, 5, '2023-04-23', 12, 3, 15.99),
(3, 1, '2023-04-23', 8, 1, 25.99),
(4, 3, '2023-04-24', 10, 2, 10.99),
(5, 4, '2023-04-24', 11, 4, 12.99),
(6, 2, '2023-04-24', 9, 1, 35.99);

-- vertically fragment table based on columns


CREATE TABLE orders_info (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE
);

CREATE TABLE order_details (


order_id INT PRIMARY KEY,
product_id INT,
quantity INT,
price DECIMAL(10,2)
);

INSERT INTO orders_info SELECT order_id, customer_id, order_date FROM orders;


INSERT INTO order_details SELECT order_id, product_id, quantity, price FROM orders;

RESULT :-

You might also like