How to Create Tables in SQLite
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/data-science-mini-degree/?zva_src=youtube-datascience-md
TRANSCRIPT
So in this video What we're going to do is learn how we can create our own data structure to go inside of a SQLite database, so far we've only looked at an existing database and can run all kinds of queries and select, select statement against a dataset that has already existed in the columns, tables are all defined. All the tables themselves are also defined. But now we are gonna look at how we can create our own database, create our own tables, and whatnot. So we are gonna be looking at how we can do that. And so in this video particularly, we are gonna learn how we can create tables, what is the syntax, what are the different data types, and what are some other kind of idems, what are some other kind of actuaries so they can assign to columns. So you will notice that I don't have the terminal yet. That's because I just have a text editor here the one that I am using is called Visual Studio Code. You can install it as part of the Anoconda but really any text editor will work. So I already have the file created called Create-tables.sql. And it's in the same folder as, it's just in a particular folder, senquote as everything else, but we're not gonna run against chinook.db we're gonna create our own database and then run it as well, so we'll see how to do that. So the first thing that we're gonna do is create a table and we're gonna create a table called student, and we're gonna give it some columns and then we are gonna call columns sunlight attribute. Create a table of students and by the way to do comments in SQL it's just either two hyphens or you can do this forward slash star and then star forward slash it's called c style comments and these are multi line. Anyway we'll just create table student so syntax to create a table is just create table and then the name of the table and I have to do this and I'm gonna split the side across multiple lines because it's easier to read.
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 me ... https://www.youtube.com/watch?v=eU1Jiu7zkBI
22720369 Bytes