怎样将sql数据库中同一表中的一列数据更改为另外一列的数据?

如题所述

第1个回答  2020-05-29
用:update
表名
set
a=c
where
c
is
not
null即可。
update
表名
set
列名=想改的值
例子:
数据库表
Card
中的某列名为date
,列中的数据都不相同,把这一列的所有数据都改为2013
update
Card
set
Date=2013
扩展资料:
注意事项
SQL中新增列或者说添加字段的语法:
alter
table
表名
add
列名
数据类型
二、例如:在表texttable中添加一列字符型字段colnew:
alter table texttable add colnew char(20)
三、添加的新列,默认值为空值NULL。需要根据需求使用SQL语句更改
1、SQL修改列的语法:
update
表名
set
字段
=
赋值
where字句(确定要修改的列)
2、实例:
update texttable set colnew = 'temp';--把所有行的 colnew列的值改为 "temp"
update texttable set colnew = 'temp' where id=1000 ;--把ID为1000的行 colnew列的值改为 "temp"
第2个回答  2020-02-09
可用update语句来更改,但要注意,两列的属性及长度应尽量保持一致,或被更改的列的长度大于另一列的长度,否则在update过程中容易报错。
1、创建测试表,插入数据:
create table test
(id int,
name varchar(10),
name1 varchar(10))
insert into test values (1,'a','s')
insert into test values (2,'b','w')
insert into test values (3,'c','x')
数据如下:
2、现在要将name1的内容更改为name中的内容,可用如下语句:
update test set name1=name;
3、更改后的结果如图(此时name和name1列的内容就相同了):
相似回答
大家正在搜