SQL constraints in SQL

4 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.59
List Price:  €65.24
You save:  €18.64
£39.95
List Price:  £55.93
You save:  £15.98
CA$68.27
List Price:  CA$95.58
You save:  CA$27.31
A$76.51
List Price:  A$107.13
You save:  A$30.61
S$68.03
List Price:  S$95.25
You save:  S$27.21
HK$391.33
List Price:  HK$547.90
You save:  HK$156.56
CHF 45.60
List Price:  CHF 63.85
You save:  CHF 18.24
NOK kr550.06
List Price:  NOK kr770.13
You save:  NOK kr220.06
DKK kr347.49
List Price:  DKK kr486.51
You save:  DKK kr139.02
NZ$84.03
List Price:  NZ$117.65
You save:  NZ$33.61
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,484.82
List Price:  ৳7,679.19
You save:  ৳2,194.37
₹4,167.13
List Price:  ₹5,834.32
You save:  ₹1,667.18
RM238.42
List Price:  RM333.81
You save:  RM95.39
₦65,297.93
List Price:  ₦91,422.33
You save:  ₦26,124.40
₨13,918.71
List Price:  ₨19,487.31
You save:  ₨5,568.59
฿1,846.97
List Price:  ฿2,585.90
You save:  ฿738.93
₺1,626.69
List Price:  ₺2,277.50
You save:  ₺650.80
B$257.91
List Price:  B$361.10
You save:  B$103.18
R942.93
List Price:  R1,320.17
You save:  R377.24
Лв91.05
List Price:  Лв127.48
You save:  Лв36.42
₩68,777.09
List Price:  ₩96,293.43
You save:  ₩27,516.34
₪190.37
List Price:  ₪266.53
You save:  ₪76.16
₱2,884.27
List Price:  ₱4,038.21
You save:  ₱1,153.93
¥7,839.25
List Price:  ¥10,975.59
You save:  ¥3,136.33
MX$862.02
List Price:  MX$1,206.90
You save:  MX$344.87
QR182.32
List Price:  QR255.26
You save:  QR72.94
P689.82
List Price:  P965.80
You save:  P275.98
KSh6,748.65
List Price:  KSh9,448.65
You save:  KSh2,700
E£2,394.60
List Price:  E£3,352.63
You save:  E£958.03
ብር2,846.33
List Price:  ብር3,985.10
You save:  ብር1,138.76
Kz41,775.97
List Price:  Kz58,489.70
You save:  Kz16,713.73
CLP$47,415.51
List Price:  CLP$66,385.51
You save:  CLP$18,970
CN¥362.26
List Price:  CN¥507.19
You save:  CN¥144.93
RD$2,936.27
List Price:  RD$4,111.01
You save:  RD$1,174.74
DA6,712.91
List Price:  DA9,398.61
You save:  DA2,685.70
FJ$112.97
List Price:  FJ$158.17
You save:  FJ$45.19
Q388.83
List Price:  Q544.39
You save:  Q155.56
GY$10,456.12
List Price:  GY$14,639.41
You save:  GY$4,183.28
ISK kr6,993.60
List Price:  ISK kr9,791.60
You save:  ISK kr2,798
DH505.76
List Price:  DH708.11
You save:  DH202.34
L888.32
List Price:  L1,243.72
You save:  L355.39
ден2,869.11
List Price:  ден4,016.98
You save:  ден1,147.87
MOP$402.79
List Price:  MOP$563.94
You save:  MOP$161.15
N$957.24
List Price:  N$1,340.22
You save:  N$382.97
C$1,839.29
List Price:  C$2,575.16
You save:  C$735.86
रु6,654.43
List Price:  रु9,316.74
You save:  रु2,662.30
S/186.47
List Price:  S/261.07
You save:  S/74.60
K192.50
List Price:  K269.52
You save:  K77.01
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,315.66
List Price:  ZK1,842.03
You save:  ZK526.37
L231.86
List Price:  L324.63
You save:  L92.76
Kč1,171.86
List Price:  Kč1,640.70
You save:  Kč468.84
Ft18,288.87
List Price:  Ft25,605.88
You save:  Ft7,317.01
SEK kr544.90
List Price:  SEK kr762.91
You save:  SEK kr218
ARS$43,678.56
List Price:  ARS$61,153.48
You save:  ARS$17,474.92
Bs346.09
List Price:  Bs484.56
You save:  Bs138.46
COP$197,009.16
List Price:  COP$275,828.59
You save:  COP$78,819.43
₡25,122.12
List Price:  ₡35,172.98
You save:  ₡10,050.86
L1,233.97
List Price:  L1,727.65
You save:  L493.68
₲371,261.88
List Price:  ₲519,796.34
You save:  ₲148,534.45
$U1,917.12
List Price:  $U2,684.12
You save:  $U767
zł201.38
List Price:  zł281.95
You save:  zł80.57
Already have an account? Log In

Transcript

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.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.