SQL server data default

Asked

Viewed 433 times

1

Hello, I am creating a table and I need to leave the expiration date as default the date 1990/01/01. someone could give me a help?

Below the code I’ve already 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

2 answers

2

I believe it is enough for you to change the value that is 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)
);

2


Just add default in the Dtexpiration column with the date in YYYYMMDD format or in the language format defined for the database, thus:

DtExpiracao datetime default ('19900101')

Browser other questions tagged

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