简体   繁体   中英

How to add constraints on a SQL TYPE

I'm a beginner, learning Oracle SQL.

I need to create a type, with constraints on the variables it contains (for example, create a boolean type constrained to true/false/null. Don't tell me that boolean exists. this is just an illustrative example)

I do not want to add constrains on each table declaration, because these problems:

  • Needs to repeat checkings each time I use the type.
  • Needs to edit each type implementation on each table each time a bug is found.

Is there a way to define a type with his own checkings?

I'm a newbie, please add an example.

I had read the documentation for declare type, and I find nothing (aside, the documentation is awful)

What you're looking for are SQL domains . Oracle doesn't support these; instead you have to put the constraints on the table definitions.

Oracle does support object types but personally I avoid them as they seem to create more trouble than they're worth.

One way we make this easier is to model using a separate tool like SQL Developer Data Modeler, which allows you to define custom domains. The tool then generates the DDL to create the tables and columns with appropriate data types and constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM