This section presents and portrays the idea of Schema.
Introduction
A composition is an assortment of named objects arranged consistently in the database.
In a database, you can't make numerous database objects with same name. To do as such, the construction gives a gathering domain. You can make numerous diagrams in a database and you can make various database objects with same name, with various construction gatherings.
A diagram can contain tables, capacities, records, tablespaces, strategies, triggers and so on. For instance, you make two distinct outlines named as "Expert" and "Individual" for a "representative" database. It is conceivable to make two distinct tables with a similar name "Representative". In this condition, one table has proficient data and different has individual data of worker. Disregarding having two tables with a similar name, they have two unique diagrams "Individual" and "Expert". Henceforth, the client can work with both without experiencing any issue. This element is valuable when there are imperatives on the naming of tables.
Let us see scarcely any orders identified with Schema:
Getting currently active schema
Syntax:
db2 get schema
Example: [To get current database schema]
db2 get schema
Setting another schema to current environment
Syntax:
db2 set schema=<schema_name>
Example: [To arrange ‘schema1’ to current instance environment]
db2 set schema=schema1
Creating a new Schema
Syntax: [To create a new schema with authorized user id]
db2 create schema <schema_name> authroization <inst_user>
Example: [To create “schema1” schema authorized with ‘db2inst2”]
db2 create schema schema1 authorization db2inst2
Exercise
Let us make two unique tables with same name yet two distinct mappings. Here, you make representative table with two distinct diagrams, one for individual and the other for proficient data.
Step 1: Create two schemas.
Schema 1: [To create schema named professional]
db2 create schema professional authorization db2inst2
Schema 2: [To create schema named personal]
db2 create schema personal authorization db2inst2
Step 2: Create two tables with the same name for Employee details
Table1: professional.employee
[To create a new table ‘employee’ in the database using schema name ‘professional’]
db2 create table professional.employee(id number, name
varchar(20), profession varchar(20), join_date date,
salary number);
Table2: personal.employee
[To create a new table ‘employee’ in the same database, with schema name ‘personal’]
db2 create table personal.employee(id number, name
varchar(20), d_birth date, phone bigint, address
varchar(200));
In the wake of executing these means, you get two tables with same name 'representative', with two distinct patterns.
