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
€42.78
List Price:  €59.89
You save:  €17.11
£37.63
List Price:  £52.68
You save:  £15.05
CA$68.74
List Price:  CA$96.24
You save:  CA$27.50
A$76.46
List Price:  A$107.05
You save:  A$30.59
S$64.18
List Price:  S$89.86
You save:  S$25.68
HK$389.80
List Price:  HK$545.76
You save:  HK$155.95
CHF 40.68
List Price:  CHF 56.96
You save:  CHF 16.27
NOK kr502.83
List Price:  NOK kr704.01
You save:  NOK kr201.17
DKK kr319.32
List Price:  DKK kr447.07
You save:  DKK kr127.75
NZ$84.85
List Price:  NZ$118.79
You save:  NZ$33.94
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,068.94
List Price:  ৳8,497.01
You save:  ৳2,428.06
₹4,407.49
List Price:  ₹6,170.83
You save:  ₹1,763.34
RM211.20
List Price:  RM295.70
You save:  RM84.50
₦76,583.41
List Price:  ₦107,222.90
You save:  ₦30,639.49
₨14,158.94
List Price:  ₨19,823.65
You save:  ₨5,664.70
฿1,617.47
List Price:  ฿2,264.59
You save:  ฿647.11
₺2,054.58
List Price:  ₺2,876.58
You save:  ₺822
B$271.51
List Price:  B$380.14
You save:  B$108.62
R882.47
List Price:  R1,235.53
You save:  R353.06
Лв83.59
List Price:  Лв117.04
You save:  Лв33.44
₩69,434.61
List Price:  ₩97,214.01
You save:  ₩27,779.40
₪166.60
List Price:  ₪233.25
You save:  ₪66.65
₱2,853.82
List Price:  ₱3,995.58
You save:  ₱1,141.76
¥7,350.27
List Price:  ¥10,290.97
You save:  ¥2,940.70
MX$932.56
List Price:  MX$1,305.67
You save:  MX$373.10
QR181.90
List Price:  QR254.68
You save:  QR72.77
P671.90
List Price:  P940.72
You save:  P268.81
KSh6,447.90
List Price:  KSh9,027.58
You save:  KSh2,579.67
E£2,397.80
List Price:  E£3,357.12
You save:  E£959.31
ብር7,107.83
List Price:  ብር9,951.53
You save:  ብር2,843.70
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$48,299.21
List Price:  CLP$67,622.76
You save:  CLP$19,323.55
CN¥356.46
List Price:  CN¥499.08
You save:  CN¥142.61
RD$3,142.90
List Price:  RD$4,400.31
You save:  RD$1,257.41
DA6,485.80
List Price:  DA9,080.64
You save:  DA2,594.84
FJ$112.74
List Price:  FJ$157.85
You save:  FJ$45.10
Q382.55
List Price:  Q535.60
You save:  Q153.05
GY$10,437.26
List Price:  GY$14,613.01
You save:  GY$4,175.74
ISK kr6,116.42
List Price:  ISK kr8,563.48
You save:  ISK kr2,447.05
DH449.92
List Price:  DH629.93
You save:  DH180
L831.49
List Price:  L1,164.15
You save:  L332.66
ден2,631.98
List Price:  ден3,684.99
You save:  ден1,053
MOP$400.73
List Price:  MOP$561.05
You save:  MOP$160.32
N$885.92
List Price:  N$1,240.36
You save:  N$354.44
C$1,836.63
List Price:  C$2,571.43
You save:  C$734.80
रु7,038.37
List Price:  रु9,854.29
You save:  रु2,815.91
S/176.64
List Price:  S/247.31
You save:  S/70.67
K211.20
List Price:  K295.70
You save:  K84.50
SAR187.58
List Price:  SAR262.63
You save:  SAR75.04
ZK1,177.09
List Price:  ZK1,648.02
You save:  ZK470.93
L217.05
List Price:  L303.89
You save:  L86.84
Kč1,046.22
List Price:  Kč1,464.79
You save:  Kč418.57
Ft16,984.83
List Price:  Ft23,780.13
You save:  Ft6,795.29
SEK kr472.98
List Price:  SEK kr662.21
You save:  SEK kr189.23
ARS$66,578.34
List Price:  ARS$93,215
You save:  ARS$26,636.66
Bs344.87
List Price:  Bs482.84
You save:  Bs137.97
COP$201,033.58
List Price:  COP$281,463.10
You save:  COP$80,429.51
₡25,201.39
List Price:  ₡35,283.96
You save:  ₡10,082.57
L1,306.73
List Price:  L1,829.53
You save:  L522.79
₲360,827.57
List Price:  ₲505,187.47
You save:  ₲144,359.90
$U1,999.90
List Price:  $U2,800.03
You save:  $U800.12
zł182.41
List Price:  zł255.38
You save:  zł72.97
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.