Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:21:19+00:00 2026-05-31T16:21:19+00:00

how can I specify a NOT NULL contraint at the end of my sql

  • 0

how can I specify a NOT NULL contraint at the end of my sql statement as I can with a UNIQUE

 CREATE TABLE test ( 
        WORKFLOW_CLASS_ID VARCHAR2(24),
        DEPT_OWNER VARCHAR2(3), 
        NAME VARCHAR2(64), 
        PRODUCT_ID VARCHAR2(24), 
        CONSTRAINT WF_WORKFLOW_CLASS_pk PRIMARY KEY (WORKFLOW_CLASS_ID), 
        CONSTRAINT dup_workflow UNIQUE (DEPT_OWNER, NAME), 
        CONSTRAINT not_null NOT NULL(PRODUCT_ID)) 

The above create string is built dynamically using schema defined in an XML document, which defines constraints in its own tag, so therefore I tack on the contraints at the end of the sql string. When I try to specify NOT NULL I get invalid identifier.

EDIT:
Below is the stucture of my xml document. This file has evolved and over time. I use it to generate DAO and Javabean boilerplate code that I cut and paste into Eclipse and for dynamically creating html forms (xml has field, size and label). It is also used for an Admin CRUD application for maintaining the backend. I recently added the <tableConstraints> tag because I wanted to add UNIQUE constraints; UNIQUE constraint could be specified at the end of the create statement. In hind sight, I should have added a <contraint> tag within my <column> tag.

<!DOCTYPE schema PUBLIC "SchemaId" "../../schema.dtd">
<schema>
  <tableName>WF_WORKFLOW_CLASS</tableName>
  <javaBean>WorkflowClass</javaBean>
  <tableAlias>wfc</tableAlias>
  <tableTitle>Workflow process definitions by department</tableTitle>
  <tableConstraints>, CONSTRAINT dup_workflow UNIQUE (DEPT_OWNER, NAME), CONSTRAINT not_null NOT NULL(PRODUCT_ID)</tableConstraints>
  <oneToMany>
        <attName>work_item_list</attName>
        <attName>work_action_list</attName>
  </oneToMany>

  <column>
        <name>WORKFLOW_CLASS_ID</name>
        <type>VARCHAR2</type>
        <size>24</size>
        <label>Work flow Class Unique ID</label>
  </column>

  <primaryKey>      
        <name>WORKFLOW_CLASS_ID</name>
        <type>timestamp</type>
  </primaryKey>

  <foreignKey>
        <name>ADMIN_BY</name>
        <table>EBITPSV.PS_NAMES_V009</table>
        <lookUpKey>badge</lookUpKey>
        <returnField>lname</returnField>
  </foreignKey>

</schema>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:21:20+00:00Added an answer on May 31, 2026 at 4:21 pm

    An not null constraint is declared inline, after each individual column name:

    CREATE TABLE test ( ... 
            NAME VARCHAR2(64), 
            PRODUCT_ID VARCHAR2(24) not null,
            ... )
    

    If you wish to name the constraint explicitly then you also do this after each column:

    CREATE TABLE test ( ... 
            NAME VARCHAR2(64), 
            PRODUCT_ID VARCHAR2(24)  
             CONSTRAINT PRODUCT_ID_NN NOT NULL,
            ... )
    

    You can of course modify the column after the table has been created:

    ALTER TABLE test
     MODIFY product_id varchar2(24) not null;
    

    Update:

    Judging by your recently posted XML script the best thing to do would be to add a sub-tag <notNull> to your <column> tag. With 2 values – e.g. 1, 0 you could add a not null constraint in the same way as you decide whether something is a varchar or not.

    The other way it would be possible is to loop through the values in your <tableConstraints> tag and run multiple alter table add constraint ... or alter table modify ... after you have created the table.

    You suggestion of adding <constraint> sub-tag in <column> and creating them all at the column level will only work for single column constraints not multiple as you need here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following weak entity (can not exist without WikiPage): CREATE TABLE WikiPageTree
I know I can specify it inline like this: CREATE TABLE dbo.MyTable ( Id
I have this joining table: CREATE TABLE [TagMap]( [intItemId] [bigint] NOT NULL, [intTagId] [bigint]
Can I add a column which is I specify as NOT NULL,I don't want
Can I specify I want the preceding character to be either (NOT A DIGIT)
SQL Server 2000 Say if I have a table like CREATE TABLE [Message] (
I very often want to use dynamic finders to specify NOT NULL. So… this
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
In code one can specify globally accessible constants/enums/etc once that can then be reused
Normally we can specify a target in the link or use javascript window.open to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.