SQL server data default

1

Hello, I'm creating a table and I need to leave the expiration date as default on the date 1990/01/01. Could someone help me?

Below the code I've created.

create table Coordenador (
    ID int NOT NULL identity(1,1)
    ,idlogin varchar(30) not null
    ,senha varchar(15) not null
    ,Nome varchar(30) not null
    ,Email varchar(100) not null
    ,Celular varchar(14) not null
    ,DtExpiracao date default getdate()
    ,constraint PK_Coordenador
        primary key (ID)
    ,constraint AK_login UNIQUE(idlogin)
    ,constraint AK_Email unique(email)
    ,constraint AK_Celular unique(celular)

);
go
    
asked by anonymous 04.04.2018 / 13:50

2 answers

2

Just add default in the DtExpiration column with the date in YYYYMMDD format or in the language format defined for the database, like this:

DtExpiracao datetime default ('19900101')
    
04.04.2018 / 14:09
2

I think it's enough for you to change the value being assigned as default :

declare @dataDefault datetime
select @dataDefault = convert(datetime, '1990/01/01')

create table Coordenador (
    ID int NOT NULL identity(1,1)
    ,idlogin varchar(30) not null
    ,senha varchar(15) not null
    ,Nome varchar(30) not null
    ,Email varchar(100) not null
    ,Celular varchar(14) not null
    ,DtExpiracao datetime default @dataDefault 
    ,constraint PK_Coordenador
        primary key (ID)
    ,constraint AK_login UNIQUE(idlogin)
    ,constraint AK_Email unique(email)
    ,constraint AK_Celular unique(celular)
);
    
04.04.2018 / 14:02