Computer Science, asked by shivanganiSingh, 9 months ago

step to create table and declare data type​

Answers

Answered by pulkitgoyal19
1

Answer:

Before we dig deeper into how to create new tables, we have to talk about a conceptual element of SQL: the different data types.

Let’s see what sorts of data we can put into an SQL table!

Note: in the current version of PostgreSQL there are more than 40 different data types. Here, I’ll introduce only the seven most important ones.

Integer. A whole number without a fractional part. Eg. 1, 156, 2012412

Decimal. A number with a fractional part. Eg. 3.14, 3.141592654, 961.1241250

Boolean. A binary value. It can be either TRUE or FALSE.

Date. Speaks for itself. You can also choose the format. Eg. 2017-12-31

Time. You can decide the format of this, as well. Eg. 23:59:59

Timestamp. The date and the time together. Eg. 2017-12-31 23:59:59

Text. This is the most general data type. But it can be alphabetical letters only, or a mix of letters and numbers and any other characters. Eg. hello, R2D2, Tomi, 124.56.128.41

Why is this so important?

Because when you create a new SQL table, you have to define which data type you will have in each column. And once it’s defined, you have to stick with it. For instance, if you set a new column with an Integer data type, you won’t be able to include text or dates or anything else. This means that you should be conscious about data types and also design your data tables (and databases) before you actually create them!

Similar questions