作业帮 > 综合 > 作业

SQLSERVER 增删改语句是如何写的?常用的都有那些函数,具体用法简单描述下!

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/08/29 23:14:54
SQLSERVER 增删改语句是如何写的?常用的都有那些函数,具体用法简单描述下!
一、增删改查SQL语法:
1.查询语句
第一种法方:
select 列名 from table(数据库表名) where(条件)
第二种法方:
select *(表示所有的列) from table(数据库表名) where(条件)
注意:列名与列名之间用逗号分开.
eg:
1.select ProductID,ProductName,Price
from Product
where Price>5.0
2.select * from Product where Price>5.0
3.如何给列加汉子名称:
格式:“‘列标题’=列名” 或 “'列名'AS 列标题”
eg:
select ProductID=‘产品编号’,ProductName,Price
from Product
where Price>5.0
select '产品编号'as ProductID,ProductName,Price
from Product
where Price>5.0
where 语句中可以使用逻辑运算符
AND OR NOT
eg:
select ProductID,ProductName,Price
from Product
where Price>=5.0 And Price高) desc(高->低)
2.向表中插入数据
语法:insert into tableName(columnName...(要插入的数据的列名)) values(expression(与columnName相对应的值))
注意:再插入数据时,对于允许为空的列可以使用NUll插入空值;对于具有默认值的列,可使用Defaulf插入默认值.
eg:
向Seller 表中插入一行数据,其中Sex字段使用默认值为‘男’,HireDate等字段均去空值.
insert into seller(saleid,saleName,sex,birthday,hireDate,address,telephone,telephone,notes)
values('s11','赵宇飞',default,'1974-07-25',null,null,null,null)
or
insert into seller(saleid,saleName,brithday)
values('s11','赵宇飞','1974-07-25')
3.修改表中的数据
语法:update tableName
set columnName=expression(...)
where search_conditions
eg:
1.将Product表中"啤酒"的价格改为4元
update product
set price=4
where productName='啤酒'(注意:一定要加条件 +“where”)
4.删除数据
语法:delete [from] tableName
where search_conditions
eg:
delete from Seller
where SaleID='s11'(注意:一定要加条件 +“where”,不然就把该表中所有的数据删除了)