mysqlÖÐĬÈÏÖµÔõôд
mysql ÖÐΪÁÐÉèÖÃĬÈÏÖµµÄÒªÁ죺½¨Éè±íʱָ¶¨ not null default ×Ӿ䣬È磺create table users (name varchar(255) not null default ‘john doe’);ʹÓà alter table Óï¾äÐÞ¸ÄÏÖÓÐ±í£ºalter table table_name alter column column_name set default default_value£¬È磺alter table users alter column name s
MySQL ÖÐÔõÑùÉèÖÃĬÈÏÖµ
ÔÚ MySQL ÖÐΪÁÐÉèÖÃĬÈÏÖµºÜÊǼòÆÓ£¬Ö»ÐèÔÚ½¨Éè±íʱ»òʹÓà ALTER TABLE Óï¾äÐÞ¸ÄÏÖÓбíʱָ¶¨ DEFAULT ×Ӿ伴¿É¡£
½¨Éè±íʱÉèÖÃĬÈÏÖµ
CREATE TABLE table_name ( column_name data_type NOT NULL DEFAULT default_value );
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL DEFAULT 'John Doe' );
µÇ¼ºó¸´ÖÆ
Õ⽫ÔÚÃûΪ users µÄ±íÖн¨ÉèÒ»¸öÃûΪ name µÄÁУ¬ÆäĬÈÏÖµÉèÖÃΪ John Doe¡£
ʹÓà ALTER TABLE Óï¾äÐÞ¸ÄĬÈÏÖµ
ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT default_value;
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE users ALTER COLUMN name SET DEFAULT 'Jane Doe';
µÇ¼ºó¸´ÖÆ
Õ⽫Ð޸ıí users ÖÐ name ÁеÄĬÈÏÖµ£¬½«ÆäÉèÖÃΪ Jane Doe¡£
ĬÈÏÖµÀàÐÍ
ĬÈÏÖµ¿ÉÒÔÊÇÈκΠMySQL Êý¾ÝÀàÐÍ£¬°üÀ¨£º
ÊýÖµ£¨ÕûÐͺ͸¡µãÐÍ£©
×Ö·û´®
ÈÕÆÚºÍʱ¼ä
²¼¶ûÐÍ
NULL£¨ÌåÏÖ¸ÃÁпÉÒÔΪ¿Õ£©
×¢ÖØ£º
ĬÈÏÖµÖ»»áÔÚ²åÈëÐÂÐÐʱӦÓ㬲»»áÓ°ÏìÏÖÓÐÐС£
ÈôÊDzåÈëµÄÖµÓëĬÈÏÖµÏàÆ¥Å䣬MySQL ½«ºöÂÔĬÈÏÖµ²¢²åÈëÌṩµÄÏÔʽֵ¡£
ʼÖÕ¿ÉÒÔËæʱʹÓà ALTER TABLE Óï¾äÐÞ¸ÄĬÈÏÖµ¡£
ÒÔÉϾÍÊÇmysqlÖÐĬÈÏÖµÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡