HomeНаука и техникаRelated VideosMore From: Caleb Curry

Oracle SQL Tutorial 12 - Intro to Constraints

480 ratings | 25603 views
As I believe I've mentioned in an earlier video, a constraint is basically a rule we can put in our database that prevents someone from putting the wrong data in. It protects our relationships and data integrity. Because the goal of these constraints are to protect our data integrity, you may hear them called integrity constraints. There are many integrity constraints we are going to talk about: NOT NULL UNIQUE PRIMARY KEY FOREIGN KRY CHECK There is also the DEFAULT attribute. These are all keywords we can add to our columns that will change the way the database works with our data and also prevents incorrect data. NOT NULL is a constraint you can put on a column that prevents nulls. A null is the absence of a value. When we say null, we are saying that every single row has to have a value for this column. UNIQUE is a constraint that makes every row have a unique value for this column. Now note, this does not require values to be put it, and it will allow multiple rows to be null. Next, we are going to talk about primary keys. What qualifies a column as a candidate key? First, not a single row should have a null for that column. Second, every row must be unique. The primary key constraint is essentially a combination of the NOT NULL constraint and the UNIQUE constraint. The foreign key constraint sets the requirement that any value in this column for any row must match a row in another column. Check constraints allow us to be more strict with what data is allowed in our database. NOT NULL and UNIQUE give some level of restriction, but what if we want something more specific? For example, what if we only want values between 0 and 100? That is where check constraints come in. When using check constraints, you give a boolean expression. A boolean expression is something that can be evaluated to true or false. It will only insert the row if the value you try to put into the row makes the expression evaluate to true. So if you put in a value too great or small, the expression will be false and the data is not allowed to be entered. The default constraint is a value you can give a column, and if for any reason when the row is created in the table a value is not provided, the default value will be given. So for example, we could have a bank account table where the balance defaults to 0. How do you actually implement these constraints when you are creating a table? In the next video we are going to be adding these to our users table. Please be sure to subscribe! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me on Patreon: http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Html code for embedding videos on your blog
Text Comments (21)
Kssm (18 hours ago)
Like for the doggo, nice doggo
Enseñando codigo en un tablero??? Que bien ahora ejecutelo y mire si le funciona......
Prvz Abbas (2 months ago)
Thank You So Much For Making DATABASE Tutorials So Intresting
Marcus Rieker (8 months ago)
Omar Aziz (1 year ago)
That relieving moment when the accent is not a thicc indian one. Thanks fam
Ahmed bashir (1 year ago)
Caleb u r the grtst, I wish if I Cud hit all the like btns ov all Ur tutorials, I wish if u. Cud make orcl forms tut too..Tnx alts 4 suport
kareem jeiroudi (1 year ago)
Your daughter?!!🤨 How old are you actually? You don't look that old at all.
JC (1 year ago)
*dog haha
A I (1 year ago)
Are constraints optional?
Caleb Curry (1 year ago)
They are by default if you make a key, such as a foreign key constraint. So if you don't want constraints, don't use keys (probably a bad idea 🙂)
Karina Carmin (1 year ago)
2:00 hahahahaha omg :'D Thank you for the video \(^o^)
Ken Igoni (2 years ago)
wait a minute Caleb, i thought Unique Key can be either a NULL or NOT NULL. verify
you have saved my behind. Thank you.
Harsh Mehta (2 years ago)
Cool. Liked your videos :)
Andrew Howe (2 years ago)
Caleb does the main oracle (the paid for version) still use sql developer? and does it still work in the same way you are showing in the videos. Basically will i be able to learn with the free oracle 11g and then be comfortable using the main oracle for databases? By the way thanks for the videos very helpful
Tyrone Nisbett (1 year ago)
I want to learn more about Dreamweaver, HTML, CSS etc.
Tyrone Nisbett (1 year ago)
I been leaning from your videos since i started college. Very , very helpful. Keep it up my friend! Do you tutor?
Andrew Howe (2 years ago)
ok thanks caleb, once again thanks for the videos, much appreciated
Caleb Curry (2 years ago)
Nearly everything (if not everything) I teach in these videos apply to the paid version.
1995texasaggie (2 years ago)
Gig 'Em
neo fit (2 years ago)

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.