1. Home
  2. Explore
  3. Computer Science
  4. SQL Basics for Beginners

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

SQL Basics for Beginners

Transcript

hey guys welcome to this live by Intellipaat I am ram and I'll be the one covering the live today so in today's session we'll be learning how SQL works so basically we'll be having a beginners tutorial for SQL basics of SQL but before we get into that please make sure to subscribe and hit the bell icon so that you don't miss any for future updates all right so this is a live for today will basically be talking about how you can learn SQL as a beginner so before we get into it let's take a look at our agenda for today's live so the first thing we will learn is data and database basically we'll have an introduction to what data is or what the database is then we'll learn what SQL is why do we need to learn SQL and then we'll discuss the different SQL concepts after which we'll move on to the basic queries you'll need to know in SQL as a beginner and then finally we move on to have a demo in SQL but you guys will get

a practical idea of how you can use the commands you just learned and finally I'll show you the further learning components where you can go ahead and learn SQL by yourself alright so let's start off with discussing or having the introduction to what data and database alright so we know data is almighty it helps us to make decisions data is everywhere from buying shopping you know so going to shopping to large-scale industries you drilling oil or whatever every aspect of a life has some kind of data and that data can be extracted so basically if you extract that data and extract the meaning out of it or the different aspects of it then you can make really meaningful decisions and this really affects the businesses since businesses has such large amounts of data going in and out of them they usually take this data and convert them into numbers or convert them into

profits and efficiency so the basically facts about a certain thing and they describe these things this data and helps us to get an insight into what the certain thing is and help us to get you know more understanding of it if you took the example of a customer you can record a lot of attributes of this customer his age his income his buying habits knowing this kind of data will help us to make decisions which will help us to make you know proper decisions that will basically increase the profits and the efficiency of the product or service we're trying to sell to this particular customer that is why data is very important now we have all of this data where will we store all of this data because we need to act on this data so when we want to act on this data we first need to decide where we're going to store this data and this is where databases come in so databases are basically dedicated storage locations where you store data you store

this data and then you basically manipulate this data manage handle this data and then you know analyze it process it and then represent this data and once you've done all of that you get really meaningful patterns or insights into this data which you can use to increase the your increase your business's profits or basically increase your efficiency and this is why data bases are also important so data bases basically manage large sets of data they help us to manipulate and update this data they help us to keep this data secure as data is our asset because you know it's very important to us as it helps us to increase our business that's why it's an asset and that's what we need to keep it secure and it basically in the end helps us to make these meaningful decisions like if you would talk about real life right well you have to make decisions when you make those decisions you think of all the facts

there are for that decisions once you know all the facts only then you can make the best decisions that is possible and that this is exactly the same case with large-scale data and companies so this is why we need data and databases so now let's introduce SQL what is SQL now you can call SQL or you can call it sequel doesn't really matter it's on your own preference it is basically a query language it is a query language that helps us to get the data and perform action on this data so we know that data is important and you know that data is stored in a database now how do we act on this data to act on this data we need to use we need to query this data like get the data we get that data and then we look at the data and then we get the specific data like suppose you have a list of customers in your database and you want to find out only a particular customer like customers from a particular city so if you want to find

out the number of customers in Delhi then you can do so using a by querying the data and this is where SQL comes in it helps us to query the data helps us to communicate with the database and helps us to man manipulate the data get the data and delete the data and many many many actions we'll talk about all of these things so let's see what happens this is a small example let's see you have a SQL statement select name from customers here customers is the database and name is a particular attribute in that database a lot of customers will have a name so we want to get all the names of all the customers in our database or our table here once you send this SQL statement to the database this database or this RDBMS or relational database management system will basically look at the query perform the query and give us an output what will the output be it will be the list of all the names of all the customers

there are like in my particular customer table there is lukas ram robert and jack all of these are the names of the customers so this is how a SQL works you write a query you give it to the database the database processes it and gives you an output all right so why SQL so you know we live in an era where data is the most valuable asset and it's being put at the heart of every decision making process like we just discuss despite of this explosion yeah so SQL is

a very popular way to get information out of the database it is the most popular way to do this and relational database are set up with a particular structure each record has a series of keys that are linked to one another in consistent ways basically these records are basically like like an example of a register a databases register and you have names for a particular person you will have his name his particular age his phone number his address it's as an example and each of these names are these whole rows will be called records and these records will have a particular key to link to them that will be used to identify them we will talk about this more than we're doing the demo it's called a primary key all right so this is why we need SQL SQL will basically help us to gather and manipulate all of this data we have a long list of tools and that are depending on SQL SQL is

widely used in all the business intelligence tools since you're going to be working if you are looking to work in the business intelligence department then you're gonna see that SQL is used almost everywhere why because business intelligence requires you to handle data and SQL helps you to handle this data and a lot of databases depend on SQL it's basically learning a query language so you can query the data really effectively alright now we know why we need SQL and what SQL is let's go-ahead and learn some of the SQL concepts let's get you an idea of what what are the different concepts in SQL so we know that SQL actually handles the data in databases now inside of those databases you might have multiple tables now tables have one of the most basic components of an SQL as you can see over here in the table we have rows columns and primary keys so let's start off with a well start with field but basically

field is the location where you store all the attributes and then the row comes rows are basically records now these records are basically you know a record of a particular detail of a particular if this table is about customers then a customer's detail suppose this customers Ram and he has a lot of details about him his age his number is phone number etc then this particular record is a row and you'll have multiple rows and the attributes

that describe this particular record are columns like suppose you have the name you have the age you have the phone number you have the address all of these are columns they're basically attributes that define the records basically columns and then you have null in value okay so whenever you are writing data into a table this particular table there is a possibility that this one of the attributes might be empty suppose you have the age when you're entering the data and into the table you do not the person does not write his age now if this particular attribute has been set as null value like not null that means that this particular attribute cannot be you know null it cannot be empty at all the second example of name so now every time you are entering data into this table you have to enter the name right because otherwise you can't identify the particular record without the name and

if you set this particular value of this attribute the name as not null then anyone who is entering the data cannot enter the data without entering the name that's how the system works if you set a particular attribute as null then it cannot accept any other value it cannot accept a 0 value or nothing value it has to have some kind of value it can be a dot also but it has to be something and that's what null value is and then constraints now constraints are important because constraints basically define a table by a few constraints as the name explains like sometimes you cannot enter a particular set of data and you can define that as a constraint like I suppose you don't want this particular set of data to be entered and then you can explain that as a constraint we'll talk more about it when we're doing a demo okay so this was tables now tables is the most basic component of SQL and if you understand

what a table is you can basically work with SQL very easily again a table is a unique set of data with consistent number of typed data attributes that your columns which are called yeah columns and each table must have a primary key now what is the primary basically a primary key is basically as an example it's an ID so suppose you have our record and you want to identify this record from somewhere so how will you identify it you can use the name but if you are you if you have an ID and you've said that ID as a primary key then you can easily identify this particular record now a primary key is unique to every record it cannot be duplicated this way it helps us to figure out or find any record without having any redundancy issues if there is a primary Keys definitely have to be in there in tables they basically help you to identify all the records and they uniquely identify the roles the records

all right now let's move on to the next concept that is relationships now the power relational database is in relations between these tables now you know obviously not going to have one table you might have two different tables you have a customer table and you have a product table because this customer is buying a particular product and this products information is stored in another table so you have these two tables with one which tells you the information about the customer and one which tells you about the product or both of these tables are stored in one particular database but this is a relationship between these two tables and that relationship is very important when two tables are joined one is always considered the parent in the relationship and the other this child so in this case customer could be the parent and the product table can be the child table and the primary key of the

table becomes a column in the child table this is basically to use to define the relationship if you the primary key that is the ID in the parent table or in the customer table will be used as a another key in the product table that will be called a foreign key all right so these are basically relation like relationships they basically define all the connection each table has to another and they're important then comes ordinality now once you understand that there is a relationship between two tables you are ready to build an understanding of the real what the relationship means now one place to start is considering the ordinality now this ordinality indicates whether the relationship from one parent table to a child is optional or not now sometimes you'll have obviously you'll have multiple tables when you're working in a database and you'll have to figure out whether a parent has a particular

relationship with the child or not you you might have like one parent might have multiple child or one parent have might have only one child etc so this ordinality basically indicates or it implies whether the relationship between the table is optional or not between the parent and the child like for example well for example there is a the relationship between a book and an owner could be optional since a book cannot can be unknown but somebody must have written it it will not be you know non-existent but somebody will write it right but there might not be a relationship between the person and the book because he might not read that book this is represented by having a zero on a relationship if it's optional zero in a relationship is optional or a straight

perpendicular line which indicates whether it is required or not so this is basically deciding whether a particular entity table has a particular relationship again or not so that is ordinality this is the relationship that parent has with a child now we come to cardinality now this describes the relationship of a child table to the parent table now cardinal Cardinal cardinality can be either one-to-one opposed or one-to-many or many-to-many and etc so they these are the different kinds of relationship that a child can have to Deb parent table all right so those are the concepts of SQL now let's move on and learn the different basic queries in SQL now there are of different basic queries which you basically would need to know when you're working with SQL alright so there are set of basic queries let's talk about them this is the first set is the DDF the data definition language now these

data definition language is used to define your table your database you have your create which is used to create the database or create the table then you have your drop command that is basically used to drop the table or the particular database now you have truncate now truncate is a little different than drop it does not like delete the whole table it rather deletes all the records in that table so if you have to if you want to do a fresh start but you want the table name to remain the same so then what you can do is or you want the attributes and the name to remain same then you can just truncate the table if you remove all the records but it will not delete the table at all you can still keep on adding but as a drop command you will be deleting the table completely so when you want to start again you'll have to create the table again but truncate you will not have to do that and then you have the alter

command which is basically used to alter it you know if you want to change a particular value from this value to that value then you can do that also then you have the comment value it is used to add comments to a data dictionary all right then comes DML that is data manipulation language this is basically used to manipulate all the details like you have used that is basically used to get into a particular database now you've entered your MySQL but you need to what is it you need to access a particular database you'll have multiple databases in your MySQL and you want to use a particular database that you'll use the use command do you have insert into come on now this insert into command is basically used to insert values into the table inside the database you'll have multiple tables and if you want to enter values into one of those tables then you have to use the insert into command did you the update

command again if you want to update a value for a particular record so suppose you have a customer his name is Robert but that was a mistake his full name is actually Robert Paulson so you wanna update it so you will basically use the update Command for that then you have delete command so if you want to remove a particular row you don't want to remove all the rows then you can use the delete command it will delete the record from the whole database table then you have select come on select come on is like very important because you're using it to query all the details from a particular table you're selecting whatever you want so select star from particular table it will list all the details from that table then comes data control language in this you can see commands like grant and revoke so grant basically gives users access privilege to database and revoke it Vidrawl's users access privileges given by the user grant come on now then you have TCL that is the transition

transaction control language where you have commits rollback save point and set transaction so commit is basically used to commit a transaction if you want to save any changes then you if you want to save a particular table whatever changes you made to that table you can use commit then roll back it basically rolled back set transition in case of any error occurs if you have an error and you don't want that error to remain then you can just use a rollback Command and we'll go back to the previous commit then you have save point now save point sets a save point basically it's like you know playing a game and you save you make a save in that game in the same way you're basically making a save in your particular database you're saving that transaction or set transaction is basically used to specify any characteristics for the transaction alright so guys these were all the different basic commands that you would

need to know at least in the start then later on you'll learn all of these commands by yourself or when you're googling stuff you'll get to know them so don't worry about that so just start it off and you'll get to know all these things by yourself or with us is that so there's something called crud operations so let's discuss them so crud operations basically means the operations that SQL can perform so there are many operations like in crud the full form is create read update and delete so you can create data into it or basically create tables and databases then you can read from these particular databases in table then you can update them and delete them so these are Basic CRUD operations alright now let's go ahead and have our demo that is the SQL demo so you can do two things over here what you can do is you can use an AWS instance or like a VM to launch ubuntu and install MySQL on that or you can just go ahead and install MySQL workbench

both work totally fine and you can just download whichever one you're comfortable with if you just comfort if you are someone new you can just download MySQL workbench and just start using it it's pretty easy but right now I'm gonna be using this particular instance I already have my SQL inside it it was a very simple command you know apt-get install MySQL server in my Linux instance and I just typed in mysql and start it up so now I have my SQL I'm inside it and my first command is going to be show databases all right so when I type in show databases I get a few default databases that are already there internally in MySQL now these are important for the whole system to function so you don't have to worry about them right now right now what we're going to do is we are going to create our own database so let me just clear the screen off and now I'm going to type in the command that will help us to create a database create database

space customer database all right now you might see a little difference here I have typed create database in capital and customer DV and without capital in lowercase well this is because I'm trying to differentiate the commands and the names so create database is my command here and customer DB is the basically the name so I'm gonna press ENTER and this will have created my customer DB so if I want to view the database like all I can do is I can type

in show databases and will show me my databases as you can see customer DB is now treated as another database all right so we have a database now we can go inside it to go inside it I'm going to use the command use so use customer underscore DB and semicolon so it tells me that database has changed so right now I am inside my database that I just created that is customer DB all right so now that we are inside our database we can go ahead and

create our table so remember inside of a database you will have multiple tables for storing different kinds of details so in this demo we are basically going to take the most easiest example that is customers relationship and the product that they're going to but you're going to be buying so I'm going to create two tables so first I am going to create the customer table and then I'm going to create the product table where I'll talk about the product details so let me start off by creating my customer table so the create table customer alright so I am going to create my customer table but I have to make sure that I put in attributes also so customer is the name of my table so I'm going to press ENTER after I create a bracket here and here I'm going to be entering all the different attributes I want in my table so one of the first attributes I want is ID because ID is very important and it helps us to identify our record so ID

int so what this basically does is it tells MySQL or MySQL that ID is going to be of the form int that is integer and then I'm going to type in not null if you remember when I talked about null before now that if type not null here that means that this particular attribute cannot be left empty once I enter details into this particular table so every time I'm entering a particular value ID cannot be left empty but right now I won't be entering any values

because I'm going to add another particular command that is Auto increase increment so Auto increment will basically help me to increment my ID every time a particular values inserted so this way I don't have to keep entering the ID and this way ID is automated so suppose I've entered my first particular customer the his ID will be one then second customer I his ideal b2 and I'm not going to be entering the value it is going to be auto incrementing it alright so once I've added the ID attribute I'm gonna go ahead and add the name attribute so name and then Varchar so this is basically your variable character and this is useful string value since the name is a string value I'm going to be entering Varchar and the particular value is Varchar 30 so that tells the system how much space is supposed to be stored for each record for the attribute name so if I am entering a name right now it should be less than 30 characters okay so now the

next attribute is going to be age and I'm gonna use int again and this is integer it's specifying that age is going to be integer and I'm gonna set this as not null also because I don't want age to be left empty if I want it to be left empty or if I don't care about it then I will not mention not null over there then I'm going to talk about the income the of the customer you know just in case if you work in a business and you get to know about the income that is a very useful fact because then you can market particular products based on the income so you have income I'm going to send it set it as int again and I'd want this value to be not null or I can leave it be because you mean you know not always find the income value and the next attribute I'm going to add is City so in which city is this particular person residing in I'm going to use var care again and I'm going to give it 30 as the particular storage

capacity for City then I want it to know what product so the product that will be you know the product this particular person buys so product he buys will also be using vodka and I'm gonna enter 30 again but I want this to be not not definitely not enough because you know product second let me correct the spelling because the day buying a particular product right all right then finally I'm going to add a primary key so you can set a primary key

by typing the command primary key and then in brackets you can mention what you want you can set it as name also but it's always preferred if you put in ID alright so that's it now I'm going to press ENTER again and I'm going to close the bracket all right so this has created my table so if I want to see if any tables have been created or not I can type in show tables and semicolon I have to show me that there is a table called customer now let me create my other table that will be my product model table so I'm gonna type in this again create table product model alright so there's a trick over here you can type in all the tribute values straight over here instead of pressing enter but if you press ENTER it becomes a little bit more clear and it will know a my SQL will not end your query until you put a semicolon it will not recognize so my scale will not recognize a query unless a semicolon is

there at the end of it so I'll press Enter that will take me down second individually add all of the attributes it makes it much more clear and easy to enter the values okay so I'm gonna add a ID again this will be my product IDs from the customer ID and I'm gonna make an ordinal also and I'm gonna make it auto increment also and then comma all right so now create an ID I just need to give my name of my product I'm gonna use var Kerrigan and here 30 I want this to be not null

then the price of the particular product because obviously we're going to be riding the price of the particular product I want this to be integer type and I want it to be not null again then okay then we have the year particularly or this particular model was created product model was created this is not that important this is just for extensive information keeping obviously this will be important when you're working in you know real environments a lot of detail not know and then after that I'm going to add customer ID so I will tell you why we are in customer ID here in a little bit so just first add custom ID int no no all right so that was it now I'm gonna create a primary key over here so my primary key here is going to be ID itself I want the ID to be again the primary key this time it will be a product ID that is the primary key of the table product model alright so I've written the particular

attributes remember the last attribute you should not put a comma otherwise it will give you a syntax error so and then semicolon bracket semicolon okay so now I have two tables so if I just type in the commands show tables again I can see I have two tables I have customer table and product model table all right so let's start adding values into the customer table and then we'll perform a few queries so you guys get our idea of all the basic queries let me clean the screen all right so to add any values into a table you have to use the command insert into so type in insert then into then space then the name of the particular table so my tables name is customer so customer since combined tables name is customer I'm going to be adding all the customer details right so let me just type in space here again and then the name age of the customer income city product and that's it so when you type in insert into then the table name

then you have to type in all the fields in which you want to enter the name details suppose I don't want to enter the name then I can leave name me but since name is not null it will give me an error if I leave out the name if I don't enter the name values now we will go ahead and and enter the values so for that you need to type in values and inside values you can start typing so whenever you're entering a particular string value make sure you write it in quotes so I'm going to enter here Lucas then comma then the age of that particular person I'm gonna enter is 22 and then the income of that person since the inter income is again integer so we don't have to mention anything so I'm gonna say that here it's around 90,000 per month it's a lot of money then city I'm going to add Delhi and in the product I'm gonna add he bought actually you have to mention daddy again in quotation marks because it's a string value so the product name is or the

product is cut key he's bought a TV all right then don't forget to enter add a semicolon also alright so then go ahead and press enter and now you have entered our row so if you want to receive this row what you can do is type in select star so star basically means all let me just do this properly select star I just typed in capital but you don't necessarily have to this is to give you guys a distinction so you guys don't get you know confuse so select star from and the table name customize my table thing and what I'm basically doing here I'm asking for everything whenever you type in star that means you're asking for every attribute I'm gonna be asking for every attribute here so select star from customer will give me everything it will give me the ID that is one name Lucas age 22 income nine ninety thousand City Delhi and productivity so if I wanted a particular thing only so if I wanted only the name and I only wanted the age

then I would type in select name comma age from the in a table name that is customer and then enter so this will now give me only the name and age all right so let me just quickly add a few more values so we can work with them this person also bought a TV okay now we'll need name B this is the H

I'm gonna add myself in alright so now if I do a select star select star from customer I miss out the s so as you can see it told me that there was no such name table as cut amar there's only customer so if I press ENTER as you can see it displays the whole table with all the details in this table alright so now we have a table we have our attributes now what we can try is we can try running a few queries over here so right now I can see that I have

two prefers so I only want one Pro cover so how do I get that one procore so as you can see those two records have two distinct values like they have different different values you can see that there are the two processors have the ID two and three their ages are different the incomes are different the cities are different the product the bots are different so what you can do is you can type in select what do you want we want everything of that particular record so I'm going to type in select star from customer so this should give me everything from the table customer but I'm going to add a clause the clause is is where so where clause will help us to target specific records so if I want to add take profit from Mumbai so I'm going to type in select star from customer where my city is going to be equal to Mumbai okay now I'm gonna press ENTER so as you can see it showed me the id3 plucker who

is from mumbai and the product he bought but if I changed it to something else suppose I typed in Lucknow I can get the profit that is from Lucknow so this is basically how you can target what particular record you want and where is the clause that you use now if I wanted to target a particular person who's bought now I don't know the particular person's name but I want to get all those people who are from the city bangaluru because my boss has asked me to get the details of all the people who from bangaluru and all of those people who have bought the board of phone from our company so I'm going to type in select star from customer where City is equal to ban guru and where the product is equal to phone so this is my query why is this I'm doing this query because you obviously will have thousands of details or thousands of records in your table at a time right now we only have four but you will have

more so as you can see the city is mangaluru and the product is formed so I want all of those people who live in the city Bangla loop and have bought a phone from my company so if I do that I can see that there is only one person that has bought a phone and he lives in Bengaluru and that is me all right so this is how you would use the via city where clause and the and operation operator all right so now let's see if I wanted all the customers but I wanted them by the rank of their income I want target all those customers who have the highest income possible so I'm gonna do a select but I only want their particular the I want to see what product they've bought so what I can do is I can type in select product or I'll forget that now let's just get the whole record so select star from customer again customize the table and where or we can just get it a select star from customer and we want to get all of the

names but we want it to be ordered by so I'm going to type in order by product now what this will order by income so now what this will do is it will scan through the whole database and will pick out all those who have the highest income and put them first now I've written it by order by income so if we'll order the whole list by the income now if you don't mention what way you want it to be ordered by now you're ordering it by income but do you want it to be in ascending order or descending order so if you leave it empty it will order everything by ascending order so I press ENTER and I can see that the lowest income comes first then the higher income than the higher income then the highest income if I wanted to be descending what I can type it in the do is type in des see descending order and this will list all the particular records in descending order so I will get all of those customers with the highest income first so this is

how you could go ahead and order your table all right let's check out a few more things there are a lot of commands you can use so let's let's try some I want to sum up all the different incomes so I want to see how much income all of them are earning so I will do select star from so I select sum so using some and inside some your writing income and then your writing which table it is coming from so select sum then the column name that is income over here and

from and in the table name and I want it to be where the product equals to phone so now what I'm doing is I'm basically calculating the income of all of those people who have bought a phone so this will give me the total income of this particular person and this particular person because they have both have bought phone that's why they are giving the total income over here if I didn't put any where clause that means it will give me income from everyone not just

the people who bought phone for everyone so now you can see the income is totally different alright so now let's see the average income so what I can do is just remove some and type in AVG this will get me in the average income of all my customers so the average income of all my customers is around 1 lakh 69 thousand that's the average now this average is pretty high because I'm earning a lot of money alright so that's the average now if you wanted to figure out the maximum income then you can just basically remove this average and type and select max the particular field that is income and from customer and you can see the maximum cost particular income over here so now if you wanted all of the details if you want the name alright so we have found a max nonsense minimum income all right so the minimum of income is 9000 now if I want to count all the people there are then I can do this I can just

go ahead just type in count and change the field here I'm gonna put this name so it's gonna count all those people so he's gonna count there are four people so if I do a select star from customer I can see we only added four records and that's why there is four now this can change like normally I can put an ID over here but preferably put a ID or a put a particular field that is not null because sometimes if you have a null value then it won't count it right so that's what put a not null value name is not null in this case and then if you wanted to find only those people distinct like you can see that there are two prefers but you do not want people to be duplicated suppose this broker was the same Prakash he just bought a different particular product so if he bought a different product let me just alter that so you can use the alter command for this particular purpose well actually you can use the

update command sorry update command so update table name is customer then set the city value equal to I want the city value to change to Mumbai all right so city value is set to Mumbai and I want to change the income also now tell you why I'm changing the income and this thing 80,000 okay so I'm changing the city and the income value so now that I've changed those actually haven't changed that I just said those values now I'm going to put a ver clause so I can target the particular record so that particular record where I'm targeting is where the product or product is equal to TV and the name is equal to rocker alright okay one second guys update so

I'm gonna update the from customer table and from customer table I want to set a few things so set a few things so city will be changing to Mumbai and the income will be changing to 80,000 so not a said this I just need to put a very close so where the name is equal to prof car and the product is equal to TV so now if I do a select star from customer I can see that there are two pluckers and this is so I changed this because it basically if you took a scenario where I

actually entered by mistake or different city and a different income it was actually the same person from the same city they just bought a different product so if that was error I can alter that error using the update command where I updated the value city and income accordingly and targeted it using the very close now if I want to see all the distinct people who bought from company that means that I only want to see people once I don't want them to see once again like I suppose a person has bought two items so then a name will come twice if I do select start but I only want distinct number of people so in actuality only three people have bought from a company but they chose four records so how I can change it is how I can show the distinct people is basically use the distinct particular keyword so it distinct and then I want distinct from name and I want to use it from the customer table alright so as you can see it will show me all the

distinct people here or if I want to see all of the details of those people also I can just put in stuff alright so now we know how to do perform all of these different commands we know how to you know basically use all the different commands here so now what we can do is we can attach a constraint to the particular product table and particular table that we create was customer so I'll type in a command and then we'll explain to you what this command does so alter table product model in product model add a constraint space model

customer FK foreign key customer ID references customer ID on delete gas kid alright so guys now added a particular constraint so what this will do is this will make the customer ID attribute in the table product model as a foreign key so this means that anytime I want to add a particular product model that does not already correspond to a customer table so if I do a select star from customer I can see that there are four customers who have bought particular products and they have particular IDs so if I want to

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent