• About Heli

HeliFromFinland

~ Heli's thoughts on Database Designing, Oracle SQL Developer Data Modeler, User Groups etc.

HeliFromFinland

Monthly Archives: May 2016

Stored Procedures, Functions, Packages and Data Modeler

31 Tuesday May 2016

Posted by Helifromfinland in Data Modeler

≈ Leave a comment

Quite often I hear a question: can I design my stored PL/SQL with Data Modeler too? I want to design the privileges etc. and I feel I should do it in Data Modeler.

You are right: you should. Any code that is stored in the database is a database object just like a table or a view and should be designed and managed. But because a stored PL/SQL is an Oracle specific feature you can only find them in Physical Model in the Browser.

Browser

You can edit a Stored Procedure by right-clicking and selecting Edit.

edit

 

And you can define the Properties and Privileges by double-clicking the name or right-clicking and selecting Properties.

Properties

 

Sometimes it is somebody else in the project that manages the content (logic) of the code or you rather use SQL Developer for it. Then the best way is simply reverse engineer the code from either the DDL file or the Data Dictionary. You can do that by selecting File|Import|DDL File or File|Import|Data Dictionary.

You can also compare the version of code you have in Data Modeler to the one in DDL or Data Dictionary. Simply select File|Import|DDL File or File|Import|Data Dictionary as you did while reverse engineering but since you already have the objects in you Physical Model instead of creating them the tool now shows how they are different from each other:

comp1

If you want to see the code that would be imported to the design, press DDL Preview. If you want to import the changes made to the version in DDL or Data Dictionary, press Merge.

If I have my stored PL/SQL in Data Modeler, I am able to design and define the privileges for them. What else? For instance if I am changing the table Orders I can first check if I have any code that needs to be changed because of that. I do that using the Search functionality. Right-click on the name of your Physical Model and select Search.

Type the table name you are planning to change and press Enter:

Search1

Select Stored Procedure from the Filter:

search2

And using the Report button and a custom report template you can generate a report showing the code that might need change after your change in table structure:

result

 

 

 

 

Naming the Not NULL contraints with a Naming Standard Template

25 Wednesday May 2016

Posted by Helifromfinland in Data Modeler

≈ Leave a comment

I have defined the naming standard for a NOT NULL Constraint in Design Properties (double-click the design name, Settings-> Naming Standards -> Templates) like this:

namingTemplates

How do I get my NOT NULL Constraints named as defined in the Template?

Check your Preferences.apply4Generate Short Form of NOT NULL Constraints must be turned off.

 

Then select the relational model from the Browser, right-click and select Apply Naming Standards to Keys and Constraints.applynamingstandars

Make sure to choose Not Null Constraints.

apply2

Now you can see the  names defined for the not null contraints in the Column Properties.

apply3

You can also see them defined in the DDL Preview.

apply5

And in the DDL itself.

apply6

 

— Heli

 

Academic Life

25 Wednesday May 2016

Posted by Helifromfinland in Events

≈ Leave a comment

As some of you might already know, I have started my PhD studies at the University of Helsinki. My research area is Big Data and Unified Databases. It has been extremely interesting but the highlight so far was last week: the 32nd IEEE International Conference on Data Engineering (ICDE  2016) was held in my home town, Helsinki. I was not just attending and working as a volunteer but I was also chairing one of the conference sessions: Research 6B: Analytics on Big Data (http://icde2016.fi/pre_program.php#Q1-1-196)! On Monday I was attending and web co-chairing/coordinating the First Europe-China Workshop on Big Data (http://udbms.cs.helsinki.fi/BigData2016/). On Friday I was attending and assisting with the Workshop on Keyword Search and Data Exploration on Structured Data, KEYS 2016, (http://keys2016.cs.helsinki.fi/).

That was a busy week but I could not find a better way to get to know the academic world! It was an amazing week!

Defining constraints for a Domain

10 Tuesday May 2016

Posted by Helifromfinland in Data Modeler

≈ 16 Comments

Using Domains is very wise: you only need to define the datatype and constraints once for a type of information. For instance username, money, or Boolean values. But how can I define a Domain with Oracle SQL Developer Data Modeler and how to use a domain?

Defining a Domain

Select Domain Administration from the Tools menu.

Press Add, define a Name, Logical type etc. for the Domain.

pic1

Press Apply and Save.

 

What if I want to define a constraint for columns of type BooleanDomain that can only have values 0 or 1?

Select the Domain you want to modify and press Modify. Press Value List.

pic2

Press Add and add the Values wanted and their Descriptions.

Press OK. Press Apply (to confirm the modification to the Domain).

 

To specify an attribute or a column with that Domain select Domain as Data Type and your domain from the list. Apply.

pic3

 

Now when you generate the DDLs for the table the column will be of the type defined in the Domain

CREATE TABLE Orders_Test

(

Customer_CustNO NUMBER (10) NOT NULL ,

OrderNo         NUMBER (10) NOT NULL ,

Invoiced        NUMBER (1)

) ;

And there will also be the DDL for defining the constraint:

ALTER TABLE Orders_Test ADD CHECK ( Invoiced IN (0, 1)) ;

 

What if I want to define a constraint ‘between 0-100 000’ for a Domain?

Define the domain Credit as explained earlier but instead of defining a Value List now press Ranges button.

pic4

Define the Begin Value (0), the End Value (100000) and the Description (Credit Range). Press Add.

pic13

 

Then define an attribute or a column using this Domain as a Data Type.

 

pic5

Now the DDLs you get will have all you defined in the Domain: the data type and the constraint:

 

CREATE TABLE Customers_Test

(

CustNO      NUMBER (10) NOT NULL ,

Name        VARCHAR2 (100) NOT NULL ,

CreditLimit NUMBER (6,2)

) ;

ALTER TABLE Customers_Test ADD CHECK ( CreditLimit BETWEEN 0 AND 100000) ;

 

This is all great but what if I want to define a check constraint with other kind of definition but a list or a range?

Defining a Check Constraint

Let’s define a Domain Name.

pic6

Whenever this Domain is used we want the column to be NOT NULL. Press Check Constraint.

If you want to define different constraints to different RDBMS types you can do that by clicking the Constraint field next to the technology chosen. If you want to define a generic constraint, select the Constraint field next to Generic Constraint.

pic7

 

Define the constraint using %element% notation:

pic8

Press OK.

 

pic9

Then Apply and OK.

pic10

Apply and Save.

 

Define an attribute or a column with a Domain Name.

pic11

And the DDLs

 

CREATE TABLE Customers_Test

(

CustNO      NUMBER (16) NOT NULL ,

Name        VARCHAR2 (200) ,

CreditLimit NUMBER (6,2)

) ;

ALTER TABLE Customers_Test ADD CHECK ( Name IS NOT NULL) ;

 

This might be a bit silly example but just to show how you can define more complex constraints using a variable (%column% in our example).

NOTE that the constraint defined in our example is different from defining a column mandatory (ALTER TABLE Customers_Test MODIFY (Name NOT NULL)) but the effect is the same: you cannot insert a row in that table without giving a value for the column Name.

Name             Null                Type

———– ——– ————-

CUSTNO      NOT NULL     NUMBER(16)

NAME                                    VARCHAR2(200)

CREDITLIMIT                      NUMBER(6,2)

 

In User_Constraints view you will find a constraint defining this column NOT NULL:

“HELI”   “SYS_C0014723”               “C”         “CUSTOMERS_TEST”      ” Name IS NOT NULL”    ” Name IS NOT NULL”    “”                “”            “”            “ENABLED”         “NOT DEFERRABLE”         “IMMEDIATE”    “VALIDATED”     “GENERATED NAME”                “”            “”            10.05.2016           “”            “”            “”            “”            3

 

And you cannot add a row without any value to the Name column:

  1. 00000 – “check constraint (%s.%s) violated”

*Cause:    The values being inserted do not satisfy the named check

*Action:   do not insert values that violate the constraint.

 

NOTE: You can also define a Default Value for a Domain. And if you have defined a Value List for that Domain the value can be chosen from that list.

pic12

CREATE TABLE Orders_Test
(
Customer_CustNO NUMBER (10) NOT NULL ,
OrderNo         NUMBER (10) NOT NULL ,
Invoiced        NUMBER (1) DEFAULT 0
) ;

 

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • October 2022
  • October 2021
  • April 2020
  • October 2019
  • October 2018
  • June 2018
  • December 2017
  • October 2017
  • September 2017
  • July 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • June 2014
  • May 2014
  • April 2014
  • January 2014
  • December 2013
  • November 2013

Categories

  • Data Modeler
  • Database design
  • Events
  • General
  • Oracle
  • SQL Developer

Meta

  • Register
  • Log in

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • HeliFromFinland
    • Join 48 other followers
    • Already have a WordPress.com account? Log in now.
    • HeliFromFinland
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...