Set a Default Value for a Column in SQLite: DEFAULT Constraint

When creating a table in SQLite, you have the option of adding constraints to each column.

One such constraint is the DEFAULT constraint.

The DEFAULT constraint allows you to specify a value to be used in the event no value is supplied for that column when a new row is inserted.

If you don’t use a DEFAULT clause, then the default value for a column is NULL.

Continue reading

How to Skip Rows that Violate Constraints When Inserting Data in SQLite

In SQLite, when you try to insert multiple rows into a table, and any of those rows violates a constraint on that table, the operation will fail.

This is to be expected, after all, that’s what the constraint is for.

But what if you just want to ignore any rows that violate constraints? In other words, if a row violates a constraint, you want SQLite to skip that row, then carry on processing the next row, and so on.

Fortunately, there’s an easy way to do this in SQLite.

Continue reading

See if a Table has a DEFAULT Constraint in SQL Server using OBJECTPROPERTY()

You can use the OBJECTPROPERTY() function in SQL Server to see whether or not a table has a DEFAULT constraint.

To do this, pass the table’s object ID as the first argument, and TableHasDefaultCnst as the second argument. The function returns a 1 or a 0 depending on whether or not it has a DEFAULT constraint.

A return value of 1 means that the table has a DEFAULT constraint, and a value of 0 means that it’s not.

Continue reading