0

I an using SQLite database and wanted to create a table like following:

Create Table EMPLOYEE ( [FirstName] [varchar](50), [LastName] [varchar](50), [FullName] [varchar](150) AS ([FirstName] + ' ' + [LastName]) );

Can it is possible to have Default value of any column (like FullName) referring to values of other columns present in same table.

UPDATED:

I tried forming CREATE TABLE statement using these IFNULL and COALESCE function but every time its failing. How should i write such CREATE TABLE statement which will have computed column. If such Computed column in CREATE statement is not supported then how should i achieve such requirement. Can anybody please give me an example

1 Answer 1

4

The DEFAULT value expression must be a constant expression and referring to other column values makes it non-constant.

You can use IFNULL() or COALESCE() when selecting the data to concatenate other column values in case value is null. For example:

SELECT IFNULL(fullname, firstname || ' ' || lastname) ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.