题目描述
存在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

本文介绍如何使用SQL语句向已存在的actor表中添加一个名为create_date的datetime类型新字段,并设置其为NOT NULL,同时默认值为’0000-00-00 00:00:00’。
527

被折叠的 条评论
为什么被折叠?



