Doubt about setting size for table fields!

Asked

Viewed 21 times

0

Hello! Follow the following code:

create table Pessoa (
   codigo_pessoa int not null primary key,
   nome nvarchar(50) not null,
   data_nascimento date not null,
   cpf int(11) not null
)

In the field of Cpf, set a size for it. However, it returns the following error: cannot specify a column width in the int data type. The int typing does not allow setting the size of the field. It is so or have some syntax error?

To solve this, I created the table this way:

create table Pessoa (
   codigo_pessoa int not null primary key,
   nome nvarchar(50) not null,
   data_nascimento date not null,
   cpf int not null
)

And I ran an Insert on this table:

insert into Pessoa (codigo_pessoa, nome, data_nascimento, cpf)
            values (1, 'João Silva', '20/02/1997', 03188888801);

However, it returns this error: Arithmetic overflow error when converting Expression to int data type. Cpf is larger than the respective field, I suppose. What happens to this Cpf field? Does anyone have any idea? Grateful for the attention!

  • 1

    You can declare the column cpf as bigint or as char(11). Each option requires different treatment for handling information.

  • As Cpf has integer numbers, but with the "mask" has characters, I was in doubt on what kind of data would be more appropriate. But, I’ve already figured out how to use it. Thank you for your attention!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.