filmov
tv
How to Create Tables in SQLite

Показать описание
TRANSCRIPT
There's one other thing that we can do that I usually like to do when we're creating new data structures and in the case you're gonna run this code over and over again if you're doing any kind of debugging, is what you can do is say create table, if not exists, and what adding this if not exists clause, does exactly what you think it does. It will create this table student unless there already is a table called student, inside a database, in which case the statements the entire statements is ignored. And we'll just ignore it. Okay, so I've just had that there just as a syntax feature that we can look at. So now we need to add columns to our database. And remember earlier when I mentioned that databases are highly structure data, well that means that all the columns have a datatypes associated with them. So we are gonna discuss some of the, we are gonna discuss three of the main datatypes. There's a fourth one but we're not gonna get into that one.
Okay, so let's, before we get into the datatypes let's first think about what kind of things you would need if you were managing suppose, like a university database system. So, we would need students, and one thing I'm gonna leave at the end is a challenge for you guys to write the create table statement for professors. We'll say create table for students so we'll need to give each of the students a unique student ID. So we'll create a column called student id. Okay, and this is, we're gonna add the datatypes later, but student ID is good thing to start with. And we'll do first name, we'll have to do names alright so, first name, middle name, if they have one, and then last name. And then some other information that might be useful to know is GPA, and email, their university email that is. So each student when you enroll will get assigned student id and then a unique university email. So, it'll be easier to find the columns, so these are the columns that we'll define here. So for student id, there are a couple of options that we can do for this one, but one of the most straightforward options to do for student id is to just say give it an integer, and sequentially as new students join in you assignment them the next available number. So we can do that. So one of the data types is integer, and it's just exactly what you think it is, like in any other programming language, it's just an integer, and then note that size of this integer might be however many bytes is required for this particular column. Okay, so that's one of the data types, integer.
Комментарии