> Can I put CHECK (Amt >=0), yet somehow allow the one or two accounts
> that can be negative to be negative?   I am assuming the answer is NO.
> Am I correct?

Yes, you're correct.

> CREATE TABLE Assets
> (       Name    text PRIMARY KEY
> ,       Amt     integer
> ,       CF      text -- Y if account can be negative, else N
>        CHECK   (CF='Y' OR Amt>= 0)
> );
>
> Is this the correct way to handle this, or is there a better way?

Yes, this is a good and virtually the only way to handle this.


Pavel

On Sat, Oct 10, 2009 at 12:02 PM, David Bicking <dbic...@yahoo.com> wrote:
> I've never had to deliberately use check constraints in my projects, but
> I would like to use them on a new projects. I've googled the subject,
> but found no good explanations.
>
> I have a table
> CREATE TABLE Assets
> (       Name    text PRIMARY KEY
> ,       Amt     integer
> );
>
> Now, for 99% of the records, the Amt can never be negative.
>
> Can I put CHECK (Amt >=0), yet somehow allow the one or two accounts
> that can be negative to be negative?   I am assuming the answer is NO.
> Am I correct?
>
> Thinking about it, I came up with this solution:
> CREATE TABLE Assets
> (       Name    text PRIMARY KEY
> ,       Amt     integer
> ,       CF      text -- Y if account can be negative, else N
>        CHECK   (CF='Y' OR Amt>= 0)
> );
>
> Is this the correct way to handle this, or is there a better way?
>
> David
>
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to