0

I would like to know how to create a default value.

For example:

CREATE TABLE something 
(
name varchar(20),
rank int
)

i would like to set the RANK value to 1.

(whenever i add new records, rank is automatically set to 1).

2

2 Answers 2

6
CREATE TABLE something 
(
    name varchar(20),
    rank int default 1
)
Sign up to request clarification or add additional context in comments.

Comments

1

If the table already exists and you want to add the default value the fastest way to do it is with ALTER TABLE like this:

ALTER TABLE something
  ALTER COLUMN rank SET DEFAULT 1;

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.