How to set a default value for one column in SQL based on another column

后端 未结 8 762
耶瑟儿~
耶瑟儿~ 2021-01-02 00:12

I\'m working with an old SQL 2000 database and I don\'t have a whole lot of SQL experience under my belt. When a new row is added to one of my tables I need to assign a defa

8条回答
  •  情歌与酒
    2021-01-02 00:35

    Yeah, trigger.

    Naturally, instead of hard-coding the defaults, you'll look them up from a table.

    Expanding on this, your new table then becomes the work_category table (id, name, default_hours), and you original table maintains a foreign key to it, transforming fom (id, work_category, hours) to (id, work_category_id, hours).

提交回复
热议问题