Introduction to Integrity Constraints in JAVA

Last updated on May 22,2019 2.6K Views


Components of Integrity Constraints in JAVA:

  •           The value cannot be null
  •           It should be unique
  •           It will have unique primary key which is used to find values on table
  •           Foreign key, in case the same primary key is there in another table

Not Null

It is a constraint that ensures that every row is filled with some value for the column, which has been specified as ‘not null’.

Basic Syntax

‘create table table_name

(column1_name datatype NOT NULL,

column2_name datatype);

*here column1 datatype cannot be NULL

Unique

It is a constraint, used for column of a table so that rows of that column are unique where it allows null value also.

Basic Syntax

‘create table table_name(

Column1_name datatype UNIQUE,

Column2_name datatype);

*Here the unique column1 will take only unique values.

Primary Key

It is a constraint, used for a column of a table so that a row in a table could be uniquely identified.

Basic Syntax

‘create table table_name(

Column1_name datatype PRIMARY KEY,

Column_2name datatype);

In the same column one won’t find any other primary key with same value. It is used for referencing the table with the same value.

Foreign Key

It is a constraint used to establish a relationship between two columns in the same or different tables. For a column to be defined as a Foreign Key, it should be defined as a Primary Key in the table, which it is referring. One or more columns can be defined as Foreign keys. This constraint identifies any column referencing the PRIMARY KEY in another table, which means you have the Primary Key in one table and find all the values in the second table as well. Then, that column in the second table is actually the Foreign Key of the second table.

Basic Syntax

‘create table table_name(

Column1_name datatype FOREIGN KEY,

Column_2name datatype);

Got a question for us? Mention them in the comments section and we will get back to you. 

Related Posts:

Introduction to JAVA/J2EE & SOA

JAVA/J2EE & SOA course

Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Introduction to Integrity Constraints in JAVA

edureka.co