2010-08-09 112 views
0

來自SQL Server,我正在學習一些Oracle語法。在Oracle SQL中創建默認約束

這是我的表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" ; 

我想預設ASOFSTARTDATETIME到SYSDATE。如何在PL/SQL中設置默認約束?

編輯

的數據類型已經得到搞砸了,所以我糾正它。

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) 
) 
; 
+0

我的數據模型被損壞和拖欠一切號(38,0)。我將列更改回其原始數據類型。 – 2010-08-09 20:00:18

+0

這很糟糕 - 我更新了我的答案以反映正確的數據類型。 – 2010-08-09 20:09:58

+0

嘿!如果我能加倍努力讓你付出努力,我會的! – 2010-08-09 20:16:06

回答

4

用途:

ALTER TABLE EXTDL_REPORTSETS 
    MODIFY last_ASOFSTARTDATETIME DATE DEFAULT SYSDATE 

我無法挖掘各10g reference documentation - this is for 11g

如果你想這樣做在CREATE TABLE語句:

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" ; 
+0

有沒有什麼辦法可以在create語句中做到這一點? – 2010-08-09 19:27:28

+0

@Raj更多:查看更新,支持文檔:http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_7002.htm#i2153108 – 2010-08-09 19:34:16