Hello, I am Shahzad and welcome to lesson number 30 please we are going to discuss about the constraints, what are the constraints in SQL. So basically SQL constraints are used to specify rules for the data in a particular table or in the cables how, let suppose we define the primary key foreign key or the auto increment key for our columns in a particular tables. Now I'm saying SHOW TABLES. So, as you can see, showing us three tables, I'm going to drop this classes table so we can create the tables from the scratch timesing drop tables and the tables name. Okay, now I'm saying SHOW TABLES. So on we have only one tables.
Okay, now I'm going to create the classes tables once again, and I'm going to use the strains for the classes tables. Now I'm saying create tables and the tables name, I'm saying classes. And now I have to define the schema here. How I'm saying CL ID. So it seemed to make sure. And now I'm saying it's not null, not null.
So this is the constraint. And also I'm saying it's auto increment field. Okay. Comma, I have to define and other columns, I'm saying CLM. I'm thinking so more Sharpie and water P and define the water. And I'm saying it's not null.
Not null. Okay? Now, you can also define the CL date or something. Here I'm seeing the date. Okay, now I have to do Find here the trending GIS. How can you define the primary key?
Now I'm saying the primary key is primary key is the CL ID. cl ID is the primary key. Now if I have to define the foreign key here because we always choose a particular student for a particular class. So now I'm saying the foreign key is I have to define another column here. I'm seeing student ID. Student ID, it's in teacher and make sure now I have to define the foreign key here.
Foreign Key student ID, and now I'm saying preferences. Sorry, references, the tables name I'm seeing students and as Id sorry as s ID. Okay now control in the Okay, remove this semicolon, all we have to use the comma separated here and after statement you will use the semicolon. So hit the enter button. So now I'm saying SHOW TABLES. As you can see, we have classes and now I'm saying select static from classes.
So as you can see, we have defined the primary key here and we have defined the CLM and also Like this. So in this way you can define your constraints your skill constraints, either it's not unique primary key foreign key check default indexing, we are not going to cover some other topics because this is the basic series like indexing is a topic you can index your columns in a particular tables, so we have a lot of concepts available in SQL. So I hope you are enjoying the series if you think we are going to be free to share our courses and also the videos. Thanks for watching.