牛客SQL练习第40题

tech2022-08-25  128

题目描述

存在actor表,包含如下列信息:

CREATE TABLE IF NOT EXISTS actor ( actor_id smallint(5) NOT NULL PRIMARY KEY, first_name varchar(45) NOT NULL, last_name varchar(45) NOT NULL, last_update timestamp NOT NULL DEFAULT (datetime('now','localtime')));

现在在last_update后面新增加一列名字为create_date, 类型为datetime, NOT NULL,默认值为’0000-00-00 00:00:00’

解答

alter table actor add `create_date` datetime not null default '0000-00-00 00:00:00'

用 alter table … add … 语句可以向已存在的表插入新字段,并且能够与创建表时一样,在字段名和数据类型后加入not null、default等限定,详情见此链接: https://www.runoob.com/sqlite/sqlite-alter-command.html

最新回复(0)