Biker John
Biker John

Reputation: 2711

Mysql default value

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).

Upvotes: 0

Views: 161

Answers (2)

Ike Walker
Ike Walker

Reputation: 65587

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;

Upvotes: 1

勿绮语
勿绮语

Reputation: 9330

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

Upvotes: 6

Related Questions