Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Hello and welcome to this new section.
And in this section we will be learning about how to use databases in a Python application.
So in this section we will learn how to work with databases.
And in this specific lecture we will learn what is a database and why exactly do we need a database.
So in order to understand what a database is and why essentially it is required.
Let's take a simple example.
So let's say you want to design a social media website.
So while creating that website, a social media website needs to have a data related to the user.
Now obviously you first need to accept that particular data or information from the user, just as you
would accept from a regular Python console.
However, the problem here is that whenever you accept some information from the user in a Python program,
that information typically gets destroyed whenever the program ends.
However, we want this information to persist, and therefore we need to store that information somewhere
so that the information remains there even after the program execution ends.
So to make the data persist, we could store it into a file, or we could store it into a database.
And we have already learnt how to store data in a file and the file handling section.
Now, a better way to store data is storing that data into a database instead of storing that data into
a file.
So let's now compare the two options for storing data which is file versus database.
So these are the major differences between storing data in a file and storing data in a database.
So data which is stored in a file is unstructured.
And data stored in a database is usually well organized.
So whenever you save some data into a file, typically that data is not as well organized or as structured
as it is in a database.
Therefore we always go ahead and prefer a database to store information more than a file database.
Enforce data integrity and files do not have a built in mechanism to enforce a data integrity.
Now what exactly is data integrity?
Let's suppose, for example, you want to accept a user's name and then save that name into a file or
a database.
Now in case of a file, what happens is if the user actually types in his name as one, two, three,
four, the file has no way to ensure what kind of data it needs to accept, and the file will happily
go ahead and accept one, two, three, four as the name of the user and it will store it.
However, with databases, we could enforce a data integrity rules, which means that we could say that
all right, as we want to accept the name of the user, the name of the user has to be in form of a
string and it cannot be a number.
So this rule enforces data integrity on the data which we store in a database, which is not possible
in case of a file.
Therefore, databases are a much more better choice when it comes to storing data, because databases
automatically enforce that data integrity.
The third point is data which is stored in a file can only be accessed and manipulated through simple
I o operations.
So let's suppose you have some kind of data which is stored in a file.
So in order to access that data and manipulate that data, you could do that by simple input output
operations, like reading data from a file and writing data to a file.
However, the data which is stored in a database can only be accessed and manipulated using SQL or SQL,
which stands for Structured Query Language.
And this Structured Query language actually allows us to perform some really complex queries over the
database.
So whenever you have to access data in a file, that could be easily performed by a simple read and
write operations.
But whenever you are dealing with databases, you need to learn a special language, which is called
as a structured query language.
Now, the Structured Query language is a little bit more complex as compared to the standard read file
and write file.
However, SQL actually gives you a more powerful way to access and manipulate the data inside the database,
and also enables you to perform complex queries on that database as well.
And the final point is, databases are optimized for performance and files can be extremely slow to
read.
So when you are dealing with a very large amount of data of hundreds of millions of users, then in
that particular case, databases are obviously more preferred.
As databases are more optimized for performance, they are much faster as compared to reading data from
files.
So this was the major difference between a file and a database.
Now let's focus on the question what exactly is a database.
So a database is nothing, but it's an organized collection of structured information or data stored
electronically in a computer system.
So a database is nothing.
But it's kind of like an organized collection of structured information.
So the data or the information which is stored in the database is highly structured.
And a collection of that structured information is a database.
Now this is electronically stored inside a memory inside a computer system.
And a database is controlled by a database management system.
So whenever you use some kind of a database along with the database, you also have something which
is called as a database management system or DBMs.
So this database management system allows you to access the database, create database and perform manipulations
inside that database as well.
Now typically a database and a database management system combines together is called as a database.
So remember that whenever we say database from here on, we typically mean the database itself combined
with the database management system.
Now once we have a basic idea of what a database is, let's now go ahead and understand how data is
actually stored in a database.
So data in a database is stored in a tabular format.
So if you recall the data inside a file is not stored in a tabular format.
It is typically written as we write some kind of text to a file.
However data inside a database is stored in form of a table which looks something like this.
Now a single database can contain multiple tables.
So let's say we are creating an application for a school management system.
And in that we want to store the information of students teachers, so on and so forth.
So in that particular case, in order to store students information, we store that information inside
of a table which looks something like this.
So this right here is a database table.
And inside of a database table you have these rows.
And then you have these columns right here.
And inside a row or inside each row we have information related to one student.
And inside each column which we have, each column is actually identified by a unique attribute.
So for example as in this case we want to store the information of a student.
A student might have an unique ID, they might have name age, and they also might have address.
So in order to represent this information we now create columns with respect to those attributes of
a student.
And then in order to save information related to that student, we create multiple rows inside this
table.
So right now this table only contains this single row which is for John.
So John has an ID one, John's age is 19 and his address is New York.
So each row inside our database table represents one entry.
So if you want to add another student here you need to go ahead and create another row here inside your
database table.
So this is how typically information is stored inside a database.
So inside a database you have a database table.
And that database table is represented by rows and columns.
So the column inside the database table represents attributes of the data which you want to store.
So in this case as we want to store students data, the students attributes are ID name, age and address.
And the rows which we have up over here.
They actually represent the data related to each individual student.
So this is how you could go ahead and store information of a student inside a database.
So once you have a brief idea about how information is stored inside a database, now let's learn how
we could access this particular information from the database.
So as I earlier mentioned, whenever you want to read a data or manipulate data inside of a database,
you need to use something which is called as a structured query language.
So let's take the previous example of the student table.
And let's say you want to access the information of a specific student here.
So in order to access this information you have to write a special syntax.
Or you have to use a special language called as Structured Query Language or SQL.
So this is what the syntax of SQL looks like.
So here let's suppose I want to get the age for the person or for the student whose name is Sean.
So in this case I write a SQL statement which would say something like all right, select age from the
student table where the name of the person is Sean.
So don't worry if you don't understand this syntax.
As of now we are going to learn how this syntax works in the lectures to come.
So when you go ahead and when you write this particular statement and execute this, you're going to
get an output as 19.
Because this statement specifically wants to get the age from the student table for the entry where
the name of the student is Sean.
And therefore we got the age for that particular student.
Now imagine if you have thousands of students here, and out of those thousands of students, you want
to find the age of a specific student.
You could easily do that by writing this SQL query right here.
So SQL is also pronounced as SQL as well.
So in this lecture we have learned the major differences between storing data in a file versus storing.
Data in a database.
We have also learned how exactly data is stored in a database by using database tables.
We have also learned how to retrieve the data from a specific database table as well.
So this was just a brief overview to give you an idea about how databases actually work.
Now in the next lecture, let's go ahead and let's learn the different types of databases and database
management systems.
So thank you very much for watching and I'll see you guys in the next one.
Thank you.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.