Data types on SQL

Hello.
I have been doing the SQL courses from data science path. I learnt that I can set data types for each column. But what does it do? Shouldn’t it prevent me to add string “asd” to a column with INTEGER data type? And “May 30th, 1990” to a DATE column?
Thanks.

Easiest way to find out is to create a table and try entering invalid data. What happens? Does SQL catch the error right away? If not, does it throw an error during a query of the table?

Yeah, I’m saying it doesn’t prevent me to enter invalid data. It just accepts them as if they were all text (but they are integer, date, etc).

image

I’m asking if it should prevent it or not. If not, then what is the purpose of having different data types?

The database is only one link in a long chain. Querying is how we fill in a dataset to be used in some process, which process will be dependent on valid data types. That is where the real problems will surface if the data is corrupt especially if the program is Java, C or any which have strict type compliace. They will raise exceptions.

So it’s okay to put wrong data types on the database, but when querying that data using some languages will trigger errors?

It would appear so. SQL does not take charge of the integrity of data types. It’s all the more reason to have validation entrenched when accepting user inputs that will be written to the database.