How can i define a column with a variable default value
I know you can put a user-defined function
but i need to get the value from another table and UDF's cannot get data
from other tables? can they? i thought i read no select or update, and
they also cannot call stored procedures
Is there a way i can set a default for a column to be something along
the lines of ...goto table , update value + 1, grab new value and return
as default?Try a trigger. That's the only way I know where you can do what you are
proposing to do...
Aneesh.
"Chris M" wrote:
> How can i define a column with a variable default value
> I know you can put a user-defined function
> but i need to get the value from another table and UDF's cannot get data
> from other tables? can they? i thought i read no select or update, and
> they also cannot call stored procedures
> Is there a way i can set a default for a column to be something along
> the lines of ...goto table , update value + 1, grab new value and return
> as default?
>|||Aneesh Aravind wrote:
> Try a trigger. That's the only way I know where you can do what you are
> proposing to do...
> Aneesh.
> "Chris M" wrote:
>
I can't use a trigger because the column is defined as not null so it
has to have something in it before the trigger will fire. I tried to
put a -1 in it so that the trigger can fire but if i do that i cannot
insert multiple rows at the same time from a select because they all go
in with -1 and it has a unique contraint on it.
I am only trying to do this so that i can make two different database
systems work near the same way so i can leave the program calling them
untouched|||Why not to use IDENTITY property?
AMB
"Chris M" wrote:
> How can i define a column with a variable default value
> I know you can put a user-defined function
> but i need to get the value from another table and UDF's cannot get data
> from other tables? can they? i thought i read no select or update, and
> they also cannot call stored procedures
> Is there a way i can set a default for a column to be something along
> the lines of ...goto table , update value + 1, grab new value and return
> as default?
>|||Alejandro Mesa wrote:
> Why not to use IDENTITY property?
>
> AMB
> "Chris M" wrote:
>
I am trying to keep it as close to another database as i can. Its being
accessed by a delphi system that still uses the BDE. There is a bug in
the BDE that will not let you use autocreated numbers as ID fields so
you have to call a stored procedure prior to post to get the number.
That is working fine. I just need to have a backup in place for things
that are not entered from delphi/bde but from an sql insert or another
program accessing the database. Everything would work just dandy if
contraints were not enforced prior to the instead of trigger. That seems
to be the thing that keeps stopping me. And actually i'm not sure why
they are enforced prior to instead of since instead of can be used to
propogate some of them.|||Use an InsteadOf trigger rather than an After trigger.
Thomas
"Chris M" <chris@._takethisout_eventsoft.com> wrote in message
news:d490vv$glq@.dispatch.concentric.net...
> Aneesh Aravind wrote:
> I can't use a trigger because the column is defined as not null so it has
to
> have something in it before the trigger will fire. I tried to put a -1 in
it
> so that the trigger can fire but if i do that i cannot insert multiple row
s at
> the same time from a select because they all go in with -1 and it has a un
ique
> contraint on it.
> I am only trying to do this so that i can make two different database syst
ems
> work near the same way so i can leave the program calling them untouched
No comments:
Post a Comment