• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default values

 
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks!,

I need to create a table with 3 columns.
the 3rd column's value should always same as 2nd column if 3rd's value is NOT mentioned.
For example



If I insert a row using following


The result of
should be following


My Question is
How do i create a table with my requirement?
All I need is the table declaration.

I've tried following and it's not working


Thanks!
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this doesn't work in your database, then you'll have to do it differently.

The best I can think of would be to create a view over your table, which would use the name value for alias if the alias was not specified:This way, if you change the name and the alias was not specified, the alias will be changed as well. This sounds good t me , but it might not be what you want. A slight disadvantage is that you need to use the table, not the view, to modify the values in the table, and the view to query the table, but it should not be an insurmountable difficulty.
 
Lakshan Dissanayake
Ranch Hand
Posts: 143
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:If this doesn't work in your database, then you'll have to do it differently.

The best I can think of would be to create a view over your table, which would use the name value for alias if the alias was not specified:This way, if you change the name and the alias was not specified, the alias will be changed as well. This sounds good t me , but it might not be what you want. A slight disadvantage is that you need to use the table, not the view, to modify the values in the table, and the view to query the table, but it should not be an insurmountable difficulty.



Uh.... Thanks!

But I was hoping some thing related to TRIGGERS.

Anyway thanks for your time
 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It probably would be possible to do it with triggers. I wouldn't recommend it, though, and I intentionally didn't mention them.

Triggers are a sort of a "magic" that happens in the background. They are hidden in the database, so easy to forget about, and they tend to interfere with new functionality. If you don't document them thoroughly, the next developer won't have a clue what's happening. Also, there are usually some situations in which triggers don't fire, which may complicate database administration or prevent use of some programming techniques.

There are lots and lots of questions over the internet (on AskTom, for example) by people who were desperate to resolve their database problem, only to find out there is a forgotten trigger somewhere that they didn't account for.

What you're trying to do with a trigger can be easily achieved by having a single point (say, a method in your project, but even a stored procedure would be better than a trigger) responsible for creating new records in the table. It's a business logic, after all, and it's generally not a good idea to have business logic code scattered all over the place (database triggers and your code, in this case).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic