The create command is utilized for creating a New database from the instance of database directory. This Create command will create all its table and objects. In DB2, each and every the database tables are put away in tablespaces, which utilize their separate group of storage.
Syntax
The syntax for creating a database is as follows:
db2 create database <db_name>
Create => Is used to create a database.
db_name => Accurate table in the db2 database.
Examples
By viewing the below example, the concept of creating a database can be easily understands.
[c]
DB2 => CREATE DATABASE Company
DB20000I The CREATE DATABASE command completed successfully.
[/c]
Here the database by name company has been successfully created.
Connecting to a database
Description
For connecting to a new database use connect database.
Syntax
The syntax for connecting to a database is as follows:
db2 connect to <database name>
Connect => Is used to connect to a database.
db_name => Accurate table in the db2 database.
Examples
By viewing the below example, the concept of connect a database can be easily understands.
[c]
DB2 => CREATE DATABASE Company
DB20000I The CREATE DATABASE command completed successfully.
db2 => CONNECT TO company
Database Connection Information
Database server = DB2/NT 10.1.0
SQL authorization ID = KALYAN.VARKALA
Local database alias = COMPANY
[/c]
Here the database by name company has been successfully created.
Dropping a database
Description
The Drop command is utilized to expel a database from the instance of database directory. This Drop command can delete all its table, objects, containers, spaces, and it's related records.
Syntax
The syntax for dropping a database is as follows:
db2 drop database <db_name>
Drop => Is used to drop a database.
db_name => Accurate table in the db2 database.
Examples
By viewing the below example, the concept of dropping a database can be easily understands.
[c]
DB2 => DROP DATABASE Company
DB20000I The DROP DATABASE command completed successfully.
[/c]
Here the database by name company has been successfully deleted.
Summary
Key Points
DB2 Creating And Dropping a Database - Used for create a new database, and also dropping the existing database.
Connecting to a database - For utilizing the existing database.