Set default value when creating an SQL table

Asked

Viewed 262 times

1

I am studying SQL Language and I am having some problems in the creation of tables, I can not set a default value in a column, whenever I apply, indicates syntax error. Can anyone help me? I have no idea what is going on... (If there are more mistakes and you can indicate, please thank you)

CREATE TABLE USUARIO
(

ID NUMERIC IDENTITY,

LOGIN VARCHAR(25) UNIQUE NOT NULL,

SENHA VARCHAR(15) NOT NULL,

DTEXPIRACAO DATE NOT NULL,

CONSTRAINT DF_DTEXPIRACAO DEFAULT(1900/01/01) FOR DTEXPIRACAO,

CONSTRAINT PK_USUARIO PRIMARY KEY (ID)

);

2 answers

2

Only some details were missing in your query, after some adjustments it would look like this:

CREATE TABLE TESTE
(
    ID NUMERIC IDENTITY CONSTRAINT PK_USUARIO PRIMARY KEY (ID),
    LOGIN VARCHAR(25) UNIQUE NOT NULL,
    SENHA VARCHAR(15) NOT NULL,
    DTEXPIRACAO DATE NOT NULL CONSTRAINT DF_DTEXPIRACAO DEFAULT('1900-01-01')
);

0


CREATE TABLE USUARIO
(
ID NUMERIC IDENTITY,
LOGIN VARCHAR(25) UNIQUE NOT NULL,
SENHA VARCHAR(15) NOT NULL,
DTEXPIRACAO DATE NOT NULL default '19000101',
CONSTRAINT PK_USUARIO PRIMARY KEY (ID)
);

Browser other questions tagged

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