SQL Constraints || Steem Alliance Community.
Hello Everyone,
Good evening everyone, how are you, i hope you all guys will happy and good. By the grace of God, i am also good.
In the world of databases, SQL is essential for managing data effectively. Among its many components, constraints are crucial for maintaining data integrity and consistency. In this post, we will discuss about SQL constraints and its types and how they ensure data quality.
Constraints are conditions that are applied on tables to ensure data integrity and data consistency. They impose necessary conditions that data must meet. Constraints make the process fast of data searching. So its help to maintain the flexible database with very low amount of data inconsistancy.
Syntax for creating constraints:
CREATE TABLE USERS (
ID datatype_name constraint_name,
USERNAME datatype_name constraint_name,
PHONE_NO datatype_name constraint_name
);
Types of SQL Constraints.
- Primary Key Constraint.
This constraint uniquely identifies each record in a table. It ensures that the primary key column contains unique data and cannot have empty/null values. Each record is uniquely identified based on the primary key constraint.
CREATE TABLE USERS(
ID INT,
NAME VARCHAR(20),
PHONE_NO INT,
PRIMARY KEY (ID)
);
- Foreign Key Constraint.
Foreign key constraints maintain referential integrity between tables for relationships between the primary key of one table and the foreign key of second table. We will understand the foreign key at the time of joining functions.
CREATE TABLE INFO(
ACCOUNT_NUM INT,
NAME VARCHAR(20),
USER_ID INT FOREIGN KEY REFERENCES CUSTOMERS(ID),
PRIMARY KEY (ACCOUNT_NUM)
);
- Check Constraints.
Check constraints are used to apply specific conditions on column values for data acceptance. A common example is restricting the age of users to be at least 18 years old. how we can use a CHECK constraint for this purpose:
CREATE TABLE USERS (
ID INT,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL CHECK (AGE >= 18),
PRIMARY KEY (ID)
);
In the above example, the CHECK constraint ensures that the AGE column must contain values that are 18 or greater. It will restrict the insertion of records if age will less than 18.
This info will provide the foundation for understanding SQL constraints and their significance in database management.
Some constrainta are not explain here. Because it is very common and easy to understand. Like not null constraints and default constraints. Not null constraint are used for restrict to enter/insert the null values in tables. Default constraint are used to give the specific value to any column.
It would be my pleasure if you will share your opinion and reviews on this topic
Please cast witness vote to @bangla.Witness or set proxy to @rme.
_
Vote @bangla.witness as witness
Set Proxy @rme as proxy
Special Thanks.
Cc: @rme
Cc: @hungry-griffin
Cc: @pennsif
Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram
🆃🅷🅰️🅽🅺 🆈🅾️🆄
Thank you, friend!


I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.
💯⚜2️⃣0️⃣2️⃣4️⃣ This is a manual curation from the @tipu Curation Project.
Also your post was promoted on 🧵"X"🧵 by the account josluds
@tipu curate
Upvoted 👌 (Mana: 2/7) Get profit votes with @tipU :)
X Promotion Post.
https://twitter.com/alimhr96/status/1755088747572457493?t=WaWrayci0ftILEeqNGDyQw&s=19