Java Reference
In-Depth Information
Creating a relational Database in MySQL
try it out
This exercise shows you how to create a simple relational database using MySQL.
1.
Download and install the MySQL Community Edition (GPL) from http://www.mysql.com/
downloads/ .
2.
Open the MySQL workbench application. See Figure 9-2.
3.
Create a new MyConnection connection by clicking the + button next to MySQL Connections, as
shown in Figure 9-3.
figure 9-2  
4.
Open MyConnection and create a schema called Employeeschema . Your screen now looks as
shown in Figure 9-4.
5.
Create two tables—Employee and Department—as shown in Figures 9-5 and 9-6.
6.
Make sure to also create a foreign key relationship between DNR in Employee and DNR in
Department. The SQL DDL corresponding to both these tables is:
CREATE TABLE IF NOT EXISTS 'EmployeeSchema'.'Employee' (
'EmployeeID' INT NOT NULL,
'Name' VARCHAR(45) NULL,
'Gender' VARCHAR(45) NULL,
'DNR' INT NULL,
PRIMARY KEY ('EmployeeID'),
INDEX 'DNRForeign_idx' ('DNR' ASC),
CONSTRAINT 'DNRForeign'
FOREIGN KEY ('DNR')
Search WWH ::




Custom Search