Hi to all,

Example:
CREATE TABLE test(name varchar(20) NOT NULL DEFAULT '');

In the above query varchar is described as NOT NULL.Then why we are inserting DEFAULT value as '' (null).

Thanks in advance,
Prem

Recommended Answers

All 6 Replies

It is not the same, NULL means no value, '' means an empty string (although no characters, it is still a string value).

If you not mentioned the DEFAULT AS ''(empty string) in VARCHAR. It automatically inserting the empty string.Then, What is the purpose of mentioning DEFAULT AS ''(empty string).

all depends what u want to achive from and with particular column

If you not mentioned the DEFAULT AS ''(empty string) in VARCHAR. It automatically inserting the empty string.Then, What is the purpose of mentioning DEFAULT AS ''(empty string).

The default value of '' will be inserted into the column if it is not in your query.

What is the purpose of inserting empty string in varchar..If u not mentioned empty string ,the sql will insert empty string as default.

Is it mandatory to insert the "Default as Empty String" in Query.

Is it mandatory to insert the "Default as Empty String" in Query.

No, it is not. You can choose to add it, and you can then choose any string as default. If you omit it, NULL is the default value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.