In data modeling, you should imagine what data types will work.
Imagine a user registration, where we will have the following information:
- Full Name
- Date of Birth
- RG
- CPF
- Address
- Number
- Complement
- ZIP CODE
- City
- State
- Active User?
How will we store this information? In a single table? These are some questions we have to think about when working with the data.
In this example, a user may have multiple addresses (1 to N), but each address belongs to only one user. So we can create two tables for storage and relate them, which would be Usuario
and Endereco
.
Now to model the tables, we should think about the kind of information we want to keep. Examples:
- Does the date of birth have letters? No. So it’s like
date
- Can RG have letters and numbers? Yes. So it will be
varchar
.
- What is the approximate number of characters for an ID? 9. You can set a slightly higher limit, because there is no national standard and each state can handle a way.
- CPF can have letters and numbers? No, just numbers. So you can store as
bigint
- Can the active user have other data than YES or NO? No. Then you can use
bit
(0 = inactive and 1 = active).
In the end, our tables will look like this:
User
- Id
int
- Full Name
varchar(50)
- Date of Birth
date
- RG
varchar(12)
- CPF
bigint
- Active
bit
Addressee
- Id
int
- Patio
varchar(50)
- Number
int
- Complement
varchar(50)
- ZIP CODE
int
- City
varchar(30)
- UF
varchar(2)
- User
int
In this example, we can note that there is a table relationship Addressee with the table User through the column UsuarioId
and the type of data is int
, because each user will have their unique numeric code automatically generated by the database system.
To know a little more about the types of data, take a look at this link:
https://www.rlsystem.com.br/tipos-dados-sql-server
I hope I’ve helped.
It depends on a number of things. Some questions help with your experience, for example: https://answall.com/q/47871/101, https://answall.com/q/48666/101, https://answall.com/q/14839/101, https://answall.com/q/121593/101, https://answall.com/q/53684/101, https://answall.com/q/57429/101 e https://answall.com/q/108842/101
– Maniero
This question is quite complex to answer. To understand you must know a little about
tipagem dinâmica
andalocação de memória
. I suggest visiting the following lines: dynamic typing, memory allocation– Solkarped
One aspect of the data analysis of your model is to determine the value domain of each of the existing data in the model. From the domain you will determine the type of data that holds the domain values.
– anonimo