If unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE

Showing Answers 1 - 13 of 13 Answers

sajida

  • Jun 10th, 2005
 

Yes.

  Was this answer useful?  Yes

indu

  • Sep 15th, 2005
 

It won't, Because SYSDATE format contains time attached with it.

rajani

  • May 11th, 2006
 

 i think  it will not allow .

If the date format is dd-mon-yy, the timestamp  will be 00:00:00.then we cannot enter sysdate for unique date column.

if we set the NLS_DATE_FORMAT to DD-MON-YY HH:MI:SS,

then we can enter sysdate into the rows of a column with uinque constraint.      so sysdate value will not  be the same always.

  Was this answer useful?  Yes

rajaselviv

  • May 18th, 2006
 

if ur answer is Yes , tell us the reason

  Was this answer useful?  Yes

Yes, It will validate the rows inserted using sysdate.  

sysdate is a function which will returs the operating system's date. 

You can use sysdate, if you are inserting one record at a time, but you can't use sysdate if you are bulk inserting into that table (It will throw an unique constraint violation exception).

-Vamsee

Yes.

Becoz sysdate contains date and time.

For example: if u create a table like this

create table ex(id number,date1 date defualt sysdate unique);

u get table created. After that if u insert rows in that table

insert into ex(id) values (id);
enter id:1
1 row created...
SQL>/
enter id:2
1 row created .....

like this, u insert some rows into that table

If u want to view the table type select * from ex; then u will get the result like this

id                      date1

1                      sep-4-08
2                      sep-4-08
........

if u want to view the date colum with time also u have to alter the session like this

alter session set nls_date_format='mm-dd-yy hh24:mi:ss';

u get session altered. now type the above SQL command

select * from ex;

id                            date1
----------------------------------

        ID DATE1
---------- -----------------
         1 09-04-08 16:40:03
         2 09-04-08 16:40:05
         3 09-04-08 16:40:06
         4 09-04-08 16:40:08
         5 09-04-08 16:40:10
         6 09-04-08 16:40:12
         7 09-04-08 16:40:16
         8 09-04-08 16:40:18
         9 09-04-08 16:40:20
        10 09-04-08 16:40:21


Like this we can create date column with unique constraint.



Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions