Create database in Redshift
In order to walk through this tutorial, please setup a new database in Redshift first. In this tutorial we will interact with a database named Tutorial01. You may use any name you like.
Configure default database for your project
Visual Paradigm supports database modeling for multiple DBMS. As you know, different DBMS support different sets of data type. Some of them are compatible with other DBMS, while some are DBMS specific. Before you start, it is important to select Redshift to be your default database so that you can use its data types when designing database. To configure the default database:
- Select Tools > DB > Database Configuration from the application toolbar.
- In the Database Configuration window, select Redshift from the list of databases on the left hand side.
- Provide the JDBC Driver File. You may click here to download the Amazon Redshift JDBC driver.
- Fill in the hostname, port, username and password of your Redshift database. Again, in this tutorial we are using a database named tutorial01.
- Click Test Connection to make sure your settings are all correct and Visual Paradigm can connect with your database. Now, we are ready for database design.
Designing your Redshift database with ERD
Let's design a 'bike store' database with ERD.
- Create an ERD by selecting Diagram > New from the application toolbar. In the New Diagram window, select Entity Relationship Diagram and click Next.
- Enter BikeShop as diagram name and then click OK to create the diagram.
- On the right hand side of the diagram you are prompted to select a model type. Just keep Physical selected. Only entities under physical model will be processed in database exporting.
- Select Entity from the diagram toolbar. Then click on the diagram to create an entity. Name it Item and press Enter to confirm editing.
- Right click on the Item entity and select New Column from popup menu.
- Enter +ID : int4 and press Enter to create a primary key column ID with int4 a type.
- By default a new column will be created upon the confirmation of the previous column. Now enter name : varchar(255) and price : float4 for the next two columns.
- Press Esc to stop adding further columns.
- An Item may have different styles, i.e. a bike jersey will have different sizes and colors. Let's create an ItemVariant entity from Item entity with one-to-many-relationship. Move the mouse pointer over the Item entity. Press on the Resource Catalog icon at the top right of shape and drag it out.
- Release the mouse button. Select One-to-Many Relationship -> Entity in Resource Catalog.
- Enter ItemVariant as entity name.
- Right click on ItemVariant entity and select New Column from popup menu, then enter the following columns.
Column Name Type +ID int4 detail varchar(255) color varchar(30) size varchar(50) qty int4
- Repeat the steps above to create the ERD as below.
- Finally, we have to store the items purchased on each order. We should relate the Order with ItemVariant instead of Item since ItemVariant is the entity storing the actual item. As each Order can have multiple ItemVariant, and each ItemVariant can be involved in multiple Order, therefore it is a many-to-many relationship. Move the mouse pointer over the Order entity. Press on the Resource Catalog icon, drag to ItemVariant and release your button. In Resource Catalog, select Many-to-Many Relationship -> Entity.
- A link entity is created between Order and ItemVariant. Rename it to OrderLine.
- Right click on OrderLine and select New Column from popup menu, then enter qty : int.
Now our ERD is ready and we can start defining the sample data for our database.
Entering sample data
Sample data enables your team to have a basic idea of the kind of data that will be stored. Sample data can also be generated to database in database generation, thus saving your time to prepare the sample in order to trial run your database. To enter sample data for your database design:
- Right click on the blank area of your ERD and select Show Table Record Editor or View Editor.
- Select the entity Customer in diagram. Now you will see the Table Record Editor listing the columns of the Customer entity.
Enter the following details of the customer into Table Record Editor.
ID (PK) firstName lastName address phone 1 John Doe email@example.com 1205, river side 12345678 2 Peter Pan firstname.lastname@example.org 306, cox road 87654321 3 Mary Jane email@example.com 52, wolf hill 12358764
- Let's move on to the Order entity. Since an Order must be placed by someone, we can pick the Customer record when filling in the sample data for Order. Press the ... button in the FK cell in Table Record Editor.
- This will bring up the sample data we entered for Customer. Choose Peter from the list. The FK value for Peter will be filled in for you in the Order record.
- Repeat the above steps to enter the following sample data.
ID (PK) date CustomerID (FK) 1 2016-04-10 17:30:15 2 2 2016-04-10 18:20:22 1
ID (PK) name 1 3R 2 Red Line
ID (PK) name 1 Components 2 Cloths
ID (PK) name price CategoryID (FK) BrandID (FK) 1 Handle Bar 799 1 1 2 Head Set 999 1 2 3 Jersey 299 2 1 4 Shpes 1599 2 1
ID (PK) detail color size qty ItemID (FK) 1 full carbon black NA 50 1 2 NA black NA 40 2 3 NA pink NA 40 2 4 short sleeve white M 150 3 5 short sleeve white L 150 3 6 short sleeve white XL 50 3 7 short sleeve white S 100 3 8 short sleeve blue M 150 3 9 short sleeve blue L 150 3 10 short sleeve blue XL 50 3 11 short sleeve blue 5 80 3 12 short sleeve blue XS 20 3 13 road black 39 40 4 14 road white 39 20 4
OrderID (PK) ItemVariantID(PK) qty 1 1 1 1 4 1 2 13 1 2 9 1 2 3 1
Once everything is ready, we can then move on to generating the database.
The database design is done. Let's generate a Redshift database from it. To generate database:
- Select Tools > DB > Generate Database... from the application toolbar.
- Specify the Output Path if you wish to keep the DDL file for your database.
- In the Generate Database field, keep Create Database selected.
- Select Export to database to let Visual Paradigm directly execute the DDL script to your database. In practice, if you want to execute changes manually, uncheck this, but for this tutorial, check it first.
- In Generate Sample Data field, select Yes (Without Auto Generated PK).
- Click OK to proceed. When finished generation, you can check Redshift and you should find the database tables created and with sample records inserted.
Amazon Redshift is a trademark of Amazon Web Services