Can we add multiple constraints on a single column?
like-
create table x(x varchar2(20), y number(2) not null,
constraint fk_cons foreign key(x) references user_info(user_id),
constraint null_cons not null(x)
)
this query is returning error ora-00904: invalid identifier....
You have wrong syntax when create null_cons constraint:
Use this (table level check constraint):
CREATE TABLE x(
    x VARCHAR2(20), 
    y NUMBER(2) NOT NULL,
    CONSTRAINT fk_cons FOREIGN KEY(x) REFERENCES user_info(user_id),
    CONSTRAINT null_cons CHECK(x IS NOT NULL)
)
Or (use NOT NULL constraint on column):
CREATE TABLE x(
    x VARCHAR2(20) NOT NULL, 
    y NUMBER(2) NOT NULL,
    CONSTRAINT fk_cons FOREIGN KEY(x) REFERENCES user_info(user_id)
)
Or (Use column level check constraint):
CREATE TABLE x(
    x VARCHAR2(20) CHECK (X IS NOT NULL), 
    y NUMBER(2) NOT NULL,
   CONSTRAINT fk_cons FOREIGN KEY(x) REFERENCES user_info(user_id)
)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With