views:

59

answers:

1

Coming from SQL Server, I am learning some Oracle syntax.

This is my table DDL

CREATE TABLE "CDR"."EXTDL_REPORTSETS"
  (
    "ID"                NUMBER(38,0) NOT NULL ENABLE,
    "SHORTNAME"         NUMBER(38,0) NOT NULL ENABLE,
    "DESCRIPTION"       NUMBER(38,0) NOT NULL ENABLE,
    "ASOFSTARTDATETIME" NUMBER(38,0) NOT NULL ENABLE,
    "ASOFENDDATETIME"   NUMBER(38,0) NOT NULL ENABLE,
    CONSTRAINT "PK_EXTDL_REPORTSETS" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CDR_DATA" ENABLE
  )
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
  )
  TABLESPACE "CDR_DATA" ;

I want to default ASOFSTARTDATETIME to SysDate. How do I set a default constraint in PL/SQL?

EDIT

The datatypes had gotten messed up, so I corrected it.

CREATE TABLE CDR.ExtDL_Reportsets(
    Id                   NUMBER(38, 0)    NOT NULL,
    ShortName            VARCHAR2(255)    NOT NULL,
    Description          VARCHAR2(500)    NOT NULL,
    AsOfStartDateTime    DATE             NOT NULL,
    AsOfEndDateTime      DATE,
    CONSTRAINT PK_ExtDL_Reportsets PRIMARY KEY (Id)
)
;
+4  A: 

Use:

ALTER TABLE EXTDL_REPORTSETS
     MODIFY last_ASOFSTARTDATETIME DATE DEFAULT SYSDATE

I'm having trouble digging up the 10g reference documentation - this is for 11g.

If you want to do it in the CREATE TABLE statement:

CREATE TABLE "CDR"."EXTDL_REPORTSETS" (
  "ID"                NUMBER(38,0) NOT NULL ENABLE,
  "SHORTNAME"         VARCHAR2(255) NOT NULL ENABLE,
  "DESCRIPTION"       VARCHAR2(500) NOT NULL ENABLE,
  "ASOFSTARTDATETIME" DATE DEFAULT SYSDATE NOT NULL ENABLE,
  "ASOFENDDATETIME"   DATE NOT NULL ENABLE,
  CONSTRAINT "PK_EXTDL_REPORTSETS" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CDR_DATA" ENABLE
)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE (
   INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
)
TABLESPACE "CDR_DATA" ;
OMG Ponies
Is there any way to do this in the create statement itself?
Raj More
@Raj More: See update, supporting documentation: http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#i2153108
OMG Ponies