Placeholder Image

Subtitles section Play video

  • Oh everyone, I hope you're having a good day.

  • My name's Kyle and this is Webb.

  • Have simplified.

  • We make the Web easy to understand, inaccessible for everyone.

  • In this video.

  • I'm going to be going over everything that you need to know about Sequel In order to do about 95% of the stuff that you'll ever need to do with Sequel, it's going to be a long video because I have quite a bit to cover.

  • So I'm going to start by talking about what sequel is and why it's important for you.

  • And then, for the majority of this video, I'm going to go over everything that you need to know about.

  • Sequel.

  • All the syntax, all the language and everything that you're going to use when you're using sequel in your day to day life and sequel is a lot like CSS and that it's very simple to understand and use and learn.

  • But the complexity of actually using it in the different things you can do with it is what makes it difficult and hard to master.

  • That's why I've included a list of exercises in the description I have again Hub Repo, That'll have a bunch of exercises with their solutions and the results so that you can work through those exercises after watching this video to get a better understanding of how sequel works and how to use it.

  • Then coming up next week, I'm going to go over the solutions for all those different questions that I have in the repo.

  • So make sure you stick around for the video next week as well, which will be linked at the end of this video if you're watching it after it's out.

  • Also, I'm going to be creating additional videos relating to topics that are more difficult to understand as we go through this.

  • So in the coming weeks and months, I'm going to have additional videos going over the more difficult topics of sequel.

  • So let me know in the comments down below, which topics you find the most confusing from this video so that I could make sure to dedicate extra time and videos to making those easier to understand for you.

  • So, without any further ado, let's get started to get started.

  • We first need to talk about what sequel is, and it's luckily fairly straightforward sequel, which stands for structured query language is essentially just a language that's designed for creating, reading, updating and deleting data from databases.

  • And pretty much any relational database manager system will use sequel as the base line for how it accesses its data for creating, reading, updating and a leading.

  • So essentially, when you learn sequel, you're able to interact with pretty much any relational database manager system using your sequel background.

  • And each relational database management system will handle higher level or lower level specific tasks that are used much less often in sometimes individual ways.

  • But everything to find in sequel is universal between all of the different database manager systems.

  • And now, before we can actually jump into learning why sequel is so important, we first need to talk about and understand what a database is and kind of how they work a little bit.

  • Essentially, a database is just a collection of data in separated out into different tables, and these tables are individual models of data, so you may have a user table.

  • You may have a product's table, you may have orders table, and all these tables will be linking to each other in order to create connections between the different data.

  • So then you have a table which contains data for a single model inside of your relation.

  • And then inside of that table you have different columns and different rose.

  • The rose are the different records of your individual models.

  • So if you have one user that will quite toe one record or row inside of your table, and two users will be to separate records or arose in that table, and then all of the properties of that user, such as their i d name email, password, those are all going to be columns inside of your database.

  • And essentially, it's just a table with columns and rows that represent your different records and different properties of those records and in the different ways that that data is related to each other, is how it becomes a relational database system, where you can link data from different tables to Data's and other tables.

  • And that's how you can create a complex data layout system using databases.

  • They're fairly straightforward and essentially just have to think about it as a collection of different tables that represent different objects inside of your data.

  • Now let's quickly talk about why it's important to learn sequel.

  • It's fairly straightforward as to why it's so important.

  • And that's because sequel deals with data and data is everywhere.

  • Almost every application that you use, whether it's on your phone, whether it's on your computer on the Internet, it has some form of data that it needs to save somewhere and databases, which your sequel are one of the greatest and easiest ways to store data for any small scale, or especially for large scale applications.

  • Which is why you see databases being used absolutely everywhere across development in any form.

  • And this is why it's so crucial to learn sequel, because as a developer, no matter what you work on, you will eventually encounter Sequel and I have to work with databases.

  • And knowing sequel at a strong level will help you significantly in your development career.

  • Now that we understand why sequel is so important and what sequel is, let's jump into my secret workbench in order to demonstrate the syntax of sequel and then talk about the different commands that we can use with sequel in order to create, read, update and delete our data.

  • If you haven't already downloaded my secret workbench.

  • I recommend checking out my last video, which I'll link up in the top corner and in the description blow that will tell you how to download my sequel server and my secret workbench on your computer in order to follow along.

  • I now have my sequel, Workbench Open and connected to my local my sequel server.

  • But I don't have any files open for me to be able to run sequel commands.

  • In order to do that, I need to click this icon in the top left corner here that allowed me to create a new sequel tab for executing queries.

  • When I click on that, open up a file for me that I can start writing a sequel inside of.

  • So now let's talk a little bit about the sequel Syntax, which is luckily really straightforward to understand.

  • There are different keywords in sequel, such as the keyword Select Where From and all of these different keywords.

  • The highlight and blew most likely for you if you're using my steeple workbench, and if using some form of other editor, they're going to highlight in a specific color so that you can distinguish your key words from your non keywords, and these key words are not at all case sensitive.

  • So, for example, this selected I have here I could write it like this select.

  • I could write all lower case.

  • I could read it with capital letters just randomly thrown throughout it.

  • It doesn't matter as long as you write the word select.

  • It is going to work as your select keyword for sequel and sequel is using a combination of keywords, table names and column names in order to string together a different query.

  • So, for example, we could just say select From then you put the table name that you want to select from.

  • It's like the column here, and essentially, this is a sequel command.

  • They have a bunch of different keywords.

  • You have different table names, different column names, and then at the end of your sequel command, you need to put a semi colon.

  • Now this is not required in every single database management system.

  • But if you wanted to write to different sequel queries in one file, you need some Nicholas to separate them.

  • So I recommend always ending a cynical into the end of your sequel statement, no matter what you're doing.

  • Also, even though the key words can be written in all caps all lower case for any other combination of uppercase or lower case, it is almost always best practice and the standard to write all of your keywords in full upper case in order to distinguish them from your column names and table names, which will most likely be in lower case format as a post uppercase.

  • Also, if you need to write a string insider sequel, use single quotes and then put the string inside of those single coach to distinguish that you have a string instead of some form of keyword or some form of table or column name.

  • So now that we have out of the way, let's get started with actually creating a database for us to use.

  • In this example, I'm going to create a database for a record company, which will have bands, albums and songs inside of it for you to be able to work with.

  • Now that we've got the syntax out of the way, we're going to create a database for a record company, which is going to contain tables for bands and albums.

  • So to get started, we need to create this database because we don't actually have any databases in our sequel server that we've created yet.

  • So what's removal of this?

  • And we're going to write the Create data base, command this command a super straight for it.

  • Just write the words create and then database and name of the database that you want to create and, in our case, what is going to create a database called Test.

  • So we put test end it with a semi colon and then inside of my super server, there's two different ways that you can run a command.

  • There's this fighting both icon on the left here that just executes absolutely everything inside of this file over here, or it will execute whatever you highlight.

  • So if you want to just execute a few commands, you can highlight them and then click this excrement lightning bolt in order.

  • Execute them or there's the second option, which is this lightning bolt with the cursor.

  • And then I'll just execute whatever statement your cursor is inside of which is the method I usually use for running sequel commands inside of Sequel server.

  • So if we just click on this icon right here, we'll create a database called Test and you'll notice nothing actually happens.

  • It doesn't look like anything is created.

  • And that's because my sequel, Workbench, doesn't actually update the u I when you create new things very quickly.

  • So if you go over to the scheme this section, this is just where your databases air listed.

  • If you click refresh, it'll actually populate our database down here of test.

  • If we open that up, you see that we have an empty test database with no tables or anything else inside of it.

  • And that's exactly what we want, since we used to create database to create that database.

  • But since we're not creating a database called Test, we actually want our database to be about something else.

  • Let's remove this database.

  • To do that, we're going to use the drop data base command, and then we just put the name of the database again that we want to drop afterwards, which is test in our case ended with a semi colon, and if we run that statement, you see that over here on the left are test data base has been removed And if you refresh it, you see it won't pop back up.

  • And that's because we've dropped that database, all of the tables inside of it and all of the data inside of it.

  • And now this is something that you were almost never going to use because dropping a database deletes all of the data inside of that database.

  • And once you have your data in your database, you almost never want to completely destroy it.

  • So this is a command that you almost never use.

  • But it's good to know that it exists in case you accidentally create a database that you don't actually want.

  • In our case, that's exactly what we did.

  • So now it was create the actual database that we want, which, as I mentioned earlier, is going to be for a record company.

  • So create database.

  • Put the name of our database, which is going to be a record company in here.

  • And if we run that and refresh down here, you now see that we have a record company database and we can start adding tables to this database and start adding data into those tables now in order to make it so that our sequel queries that we're running over here in our file actually run against the database that we just created.

  • We need to tell sequel that we're going to use that database and to do that, we just used the use command.

  • So we type and use and in the name of the database that we want to run our queries on.

  • So in this case, we just want to run them on the record company database that we just created.

  • And if we just hit that to execute, we're now using the record company database and you see that it is bowled over here in my sequel, Workbench, which tells us that we're now using that data base.

  • So we run commands such as creating tables or adding data.

  • It'll add it and create it on the record company database.

  • Otherwise, it won't actually know what database we want to run these commands on.

  • So now we can work on creating our first table.

  • This is going to be done in a very similar fashion toe.

  • How create database was done.

  • But instead of using database, where is going to use create table and then the name of the table that we want to create, and we're just going to do a test table to start here.

  • And now, as I mentioned, earlier tables have columns inside of them that represent the different properties of the object that it's representing.

  • So when we create our table, we need to tell it what columns we wanted to create with.

  • So we create parentheses, and inside of these parentheses, we're going to put the different columns that we want for our table.

  • So, for example, in this table we're just going to add one calm.

  • She's gonna call it a test column, and then we need to give that column a type because our database needs to know what type of data it's storing.

  • For example, is it going to be a string?

  • Is that imager?

  • Is it a date floating point number?

  • We need to tell our database what type of data that holds.

  • So in our case, what she's into and again, since this is a key word, I like to keep it all upper case in order to distinguish it from my column names and table names, and we don't need to end any of this with a semi colon because all of this three lines right here is a single sequel command.

  • So we just want to put the sequel, the semi colon at the end of that command.

  • And this inside of here is not actually a command, so we don't want to end it with Symbicort.

  • Otherwise, we're going to get an error.

  • So now if we put our cursor inside of this command click to execute it, and if we refresh our scheme over here on the left, you'll see that we now have a little drop down by our tables and we have a test table and inside of that table in our columns we have our test column, which is a type of imager, and that's awesome.

  • But let's say we want to add another column to our table.

  • We forgot to add it in the beginning, and we don't want to go back and change this create table because we already have data in there, and if we recreate the table, we're going to lose that data.

  • So we have a command called altar table, which will allow us to change properties of our table after we create it.

  • So we just type in altar table and then the name of the table that we want to alter in our example.

  • It's going to be the test table, and then we tell it what we want to do.

  • So we're going to tell you want to add, and we want to add a calm So we're gonna put the column name here where it's gonna call it another column.

  • And then we say what type we want that calm to be.

  • And in our case, we're going to use a string, which in sequel there's many different ways to determine a string.

  • But the easiest way is using a bar char, which essentially says this is a variable length character ray, which is essentially just what a string is.

  • And then we need to tell the var char the maximum length that it could be.

  • So our case will just say 255 is the maximum length that our string will be.

  • So this will create a string column with a max length of 2 55 that is going to be named another column, and then we'll end that with a semi colon and you'll notice that I've created a line break in here.

  • I added this onto another wine and sequel.

  • Actually doesn't care about lying breaks in the statement.

  • It just reads it until it sees this semi corn.

  • So I could put as many line breaks in here is I wanted to, and it would still work just fine, even if I had it on multiple lines or all in one line.

  • So now if we run that, refresh our schema, you'll see that we now have another comb added to our columns of our test database, and that's great.

  • We now know how to create database tables, and we know how to add columns to those tables after we've created them.

  • And that's perfect.

  • So now, since we have this test table and we don't actually want it, let's look at dropping that table, which works exactly the same as dropping a database.