An information base composition is the skeleton structure that speaks to the sensible perspective on the whole data set. It characterizes how the information is coordinated and how the relations among them are related. It forms all the requirements that are to be applied to the information.
Creating a Schema
You can make a pattern in Apache Derby utilizing the CREATE SCHEMA articulation.
Syntax
Following is the linguistic structure to the CREATE SCHEMA articulation.
CREATE SCHEMA schema_name AUTHORIZATION id
Example
Following model makes a composition named my_schema in Derby information base.
ij> CREATE SCHEMA AUTHORIZATION my_schema;
0 rows inserted/updated/deleted
At that point, you can make a table in this pattern as demonstrated underneath.
ij> CREATE TABLE my_schema.Emp ( Id INT NOT NULL GENERATED ALWAYS AS IDENTITY,
Name VARCHAR(255),
Salary INT NOT NULL,
Location VARCHAR(255),
Phone_Number BIGINT
);
> > > > > 0 rows inserted/updated/deleted
You can confirm the rundown of constructions utilizing the SHOW SCHEMAS inquiry here you can discover the rundown of compositions made.
ij> show schemas;
TABLE_SCHEM
------------------------------
APP
MY_SCHEMA
NULLID
SQLJ
SYS
SYSCAT
SYSCS_DIAG
SYSCS_UTIL
SYSFUN
SYSIBM
SYSPROC
SYSSTAT
12 rows selected
You can drop a current pattern utilizing the DROP SCHEMA articulation.
Syntax
Following is the grammar of DROPS SCHEMA articulation.
DROP SCHEMA my_schema RESTRICT;
Example
You can erase a composition in particular if doesn't have any articles in it. To erase the pattern, erase all the tables in it and erase the diagram.
ij> DROP TABLE my_schema.Emp;
0 rows inserted/updated/deleted
Following model drops the above made pattern.
ij> DROP SCHEMA my_schema RESTRICT;
0 rows inserted/updated/deleted
JDBC Example
Following JDBC model makes and drops a pattern named my_schema.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class CreateSchemaExample {
public static void main(String args[]) throws Exception {
//Registering the driver
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//Getting the Connection object
String URL = "jdbc:derby:sampleDB;create=true";
Connection conn = DriverManager.getConnection(URL);
//Creating the Statement object
Statement stmt = conn.createStatement();
stmt.execute("CREATE SCHEMA AUTHORIZATION my_schema");
//Executing the query
String query = "CREATE TABLE my_schema.Employees( "
+ "Id INT NOT NULL GENERATED ALWAYS AS IDENTITY, "
+ "Name VARCHAR(255), "
+ "Salary INT NOT NULL, "
+ "Location VARCHAR(255), "
+ "PRIMARY KEY (Id))";
stmt.execute(query);
System.out.println("Table created in schema");
stmt.execute("DROP TABLE my_schema.Employees");
stmt.execute("DROP SCHEMA my_schema RESTRICT");
System.out.println("Schema dropped");
}
}
Output
On executing, the above program produces the accompanying model.
Table created in schema
Schema dropped