Results 1 to 4 of 4

Thread: default value

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    2

    default value

    I am using stored procedures to create a new user in my data base. I want the "CreatedDate" field filled in automatically, but I am not sure of the best way to do this.
    I am very new to SQL. Is there a way to set the default value for the field to the date?

    Any help is appreciated

  2. #2
    Join Date
    Mar 2003
    Posts
    468
    don't know the database version you are using but most databases will allow you to assign a default value for a column in a table.

    If you insert into the table without the value for this column it will pull from the default.

    so , in oracle the following sequence of events will create a table with a default value of the current date to the column createddate.

    28-FEB-05 : JKOOPMANN@k10gutf8 > create table t1 (userid number, createddate date default sysdate);

    Table created.

    28-FEB-05 : JKOOPMANN@k10gutf8 > insert into t1 (userid) values (1);

    1 row created.

    28-FEB-05 : JKOOPMANN@k10gutf8 > select * from t1;

    USERID CREATEDDA
    ---------- ---------
    1 28-FEB-05

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    if it is sql server

    create table t1 (userid int, createddate datetime default getdate())

    insert into t1 (userid) values (1)

    select * from t1
    --result
    userid,createddate
    1,2005-02-28 15:14:36.077

  4. #4
    Join Date
    Feb 2005
    Posts
    2
    that worked I was using date() for the default box.

    THANK YOU!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •