SQL Server增删改查语句

如题所述

增加 insert into 表(列名1,列名2,列名3...) values(值1,值2,值3......) 删除 delete from 表 where 列名=条件 修改 update 表 set 列名=值 where 列名=条件 上面几个是完整的形式~
麻烦采纳,谢谢!
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-08-05
插入数据:insert into 表名【(字段名1,字段名2,….)】 values(值1,值2,….) 更新数据:update 表名 set 字段名=值,字段名=值 【where 条件】 删除数据:delete 表名【where 条件】 查询数据:select * from 表名 【where 条件】 【】为可选项
第2个回答  2017-01-12
最简单的方法是使用struts或jsf等mvc的框架,本身就是一个实现。如果自己实现,比较复杂的就是要自己写一个总控制器,接受所有用户的请求,进行分发给其他servlet或直接进行页面跳转。不建议自己实现,建议使用一个mvc框架
第3个回答  2016-08-01
第一种法方:
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<=10.0
2.使用字符串模糊匹配
格式:
expression[not] like 'string'(escape"换码字符")
3.使用查询列表
如果列的取值范围不是一个连续的区间,而是一些离散的值,此时就应使用 SQLServer 提供的另一个关键字 IN 。
语法格式:column_name [not] IN (value1,value2....)
eg:
select SaleID,SaleName,Sex,Birthday,HireDate,Address
form Seller
where SaleID IN('S01','S02',S07)
4.空值的判定
在SQL Server中,通过null。
5.top 和 distinct
语法:select top integer || top interger percent columnName
from tableName
eg:
分别从Customer表中检索出前5个及表中前20%的顾客信息。
select top 5 *
from Customer
select top 20 percent *
from Customer
查询Product 表中价格最高的6种商品。
eg:
select top 6 *
from Product
order by price desc
asc(低—>高) 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”,不然就把该表中所有的数据删除了)
相似回答