11.更新数据记录

-- 更新update语句对数据进行修改
/*
	update table_name
	set column1=value1,
		column2=value2,
		...columnN=valueN
	where condition
*/

/*
	将students的xy字段修改为信息学院
*/
go
update students
set xy='信息学院'
go

-- 将表students的xy数据字段的值为'信息学院' zy字段修改为计算机科学与技术
update students
set xy='信息',
	zy='计算机科学与技术'


-- 更新指定的数据
go
update students
set xy='信息',
	zy='计算机科学与技术'
where sno='020102' -- 同一行

/*	
	更新数据字段中为null的数据信息
	update table_name
	set column1=value1,
		column2=value2,
		...
		columnN=valueN
	where column is null  不能用等于可以用安全等于
*/

-- 将zy为null的数据记录修改为网络工程
go
update students
set zy='网络工程'
where zy is null
go

-- 更新数据表中前n条信息
/*
	update top(n) table_name
	set column1=value1,
		column2=value2,
		...
		columnN=valueN
	top(n) 更新数据表中的前n条记录
*/

-- 将student表前两条数据记录的xy数据字段修改为"软件学院"
update top(2) student
set xy='软件学院'

猜你喜欢

转载自blog.csdn.net/qq_53183608/article/details/121713026