我是初学的学生,有这样一个题目,在SPJ表中新增一名为SDATE的属性列,对该表中的每一个元组在SDATE属性列上填上现时的日期和时间。
我是这样做的
ALTER TABLE SPJ
ADD SDATE DATETIME
UPDATE SPJ
SET SDATE = 'YYYY-MM-DD hh:mm:ss';得到的提示:
从字符串转换日期和/或时间时,转换失败。
我是想应该不用在输入20081029****这样的数字,系统自动添加现时的时间和日期的。不知道这样行不行?我上面的哪里错了?
谢谢

解决方案 »

  1.   

    200分还是奴隶,CSDN更新的太慢了.
      

  2.   

    可以将列的默认值设置为GETDATE()或
    UPDATE SPJ 
    SET SDATE =GETDATE()
    WHERE ...
      

  3.   


    小人仍然不解~~怎样将列设置默认值呢?where?有什么条件吗?
      

  4.   

    --添加字段, 名 pdate, 不能为空, 默认值为当前日期时间 
    pdate datetime not null default getdate() 
      

  5.   

    完整一点use test --使用数据库 testgo 
    create table t --建 t 表 

    --添加字段, 名 id, 并定义为识别字段, 且设为主键 
    id int identity 
    constraint pk_t primary key, --添加字段, 名 title, 长度为 varchar 255, 不能为空, 默认值为空格 
    title varchar(255) not null default ' ', --添加字段, 名 content, 长度 varchar 4000, 不能为空, 默认值为空格 
    content varchar(4000) not null default ' ', --添加字段, 名 pdate, 不能为空, 默认值为当前日期时间 
    pdate datetime not null default getdate() 

    go 
    --授权给用户(组) 
    grant all on t to dbo 
    go 
      

  6.   

    完整一点use test --使用数据库 testgo 
    create table t --建 t 表 

    --添加字段, 名 id, 并定义为识别字段, 且设为主键 
    id int identity 
    constraint pk_t primary key, --添加字段, 名 title, 长度为 varchar 255, 不能为空, 默认值为空格 
    title varchar(255) not null default ' ', --添加字段, 名 content, 长度 varchar 4000, 不能为空, 默认值为空格 
    content varchar(4000) not null default ' ', --添加字段, 名 pdate, 不能为空, 默认值为当前日期时间 
    pdate datetime not null default getdate() 

    go 
    --授权给用户(组) 
    grant all on t to dbo 
    go