
工具/材料:以Management Studio为例。
1、首先在桌面上,点击“Management Studio”图标。
2、然后在“Management Studio”界面中,点击左上角的“新建查询”按钮。
3、之后在查询界面中,输入删除表中性别为男的记录的sql语句,“delete from Student where sex ='男' ”。
4、接着在查询界面中,点击“执行”按钮。
5、最后在查询界面中,显示成功删除2行记录。
1、数据库增加数据:
1)插入单行
insert [into] <表名>(列名) values (列值)
例:insert into t_table (name,sex,birthday) values ('开心朋朋','男','1980/6/15')
2)将现有表数据添加到一个已有表 insert into <已有的新表>(列名) select <原表列名>from <原表名>
例:insert into t_table ('姓名','地址','电子邮件')
select name,address,email from t_table
3)直接拿现有表数据创建一个新表并填充 select <新建表列名>into <新建表名>from <源表名>例:select name,address,email into t_table from strde
2、数据库删除数据:
1)删除<满足条件的>行
delete from <表名>[where <删除条件>]。
例:delete from t_table where name='开心朋朋'(删除表t_table中列值为开心朋朋的行)
2)删除整个表 truncate table <表名>
truncate table tongxunlu
注意:删除表的所有行,但表的结构、列、约束、索引等不会被删除;不能用语有外建约束引用的表
3、数据库修改数据 update <表名>set <列名=更新值>[where <更新条件>]
例:update t_table set age=18 where name='蓝色小名'
4、数据库查询数据:
1)精确(条件)查询
select <列名>from <表名>[where <查询条件表达试>] [order by <排序的列名>[asc或desc]]
2)查询所有数据行和列。例:select * from a
说明:查询a表中所有行和列
3)使用like进行模糊查询
注意:like运算副只用于字符串,所以仅与char和varchar数据类型联合使用
例:select * from a where name like '赵%'
说明:查询显示表a中,name字段第一个字为赵的记录
4)使用between在某个范围内进行查询
例:select * from a where nianling between 18 and 20
说明:查询显示表a中nianling在18到20之间的记录
5)使用in在列举值内进行查询
例:select name from a where address in ('北京','上海','唐山')
说明:查询表a中address值为北京或者上海或者唐山的记录,显示name字段
扩展资料:
插入之前需要创建数据表,创建方式如下:
CREATE TABLE 表名称
(
列名称1 数据类型,
列名称2 数据类型,
列名称3 数据类型,
....
)
例如:--流程步骤定义表
create table T_flow_step_def(
Step_no int not null, --流程步骤ID
Step_name varchar(30) not null, --流程步骤名称
Step_des varchar(64) not null, --流程步骤描述
Limit_time int not null, --时限
URL varchar(64) not null, --二级菜单链接
Remark varchar(256) not null,
)
参考资料:百度百科-sql语句大全
数据库删除语句如下:
1、delete。基础用法:delete from table(表名)。这个用于删除有明确定义的数据或者整个表的数据。比如:id是唯一不可重复的,delete from Student where id=5,即把id=5的唯一的一条数据删除。
2、rop基础用法:drop table +表名称、drop database +数据库名称、drop index +索引名称、drop view +视图名称(*在不同数据库中写法不一定是一样的),只针对删除表来说,delete用于删除整个表的数据以及结构。即把整个表彻底删除,表中的数据和字段等等全部被删除。
3、truncate基础用法:truncate table +表名称。删除表中的全部数据,包括占用的id也会全部清除。表结构不会改变,一般来说想重新往表中导入数据,就会用到这个方法。
数据库删除语句的注意事项。
用delete语句删除掉的数据,原本的被占用id并不会被删除。意思是你删除掉了id中1-10的数据,你再往里加数据,id就是从11开始。所以有些不太熟练数据库的入门者,就可能会看到id断断续续(1,5,7,8,11)排序,有可能是因为使用了detele删除了某些数据。在删除数据之前,可以使用SELECT语句对DELETE语句中的WHERE子句进行测试,这样可以对即将删除的数据进行验证,保证不会勿删。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)