增删改查sql语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了增删改查sql语句相关的知识,希望对你有一定的参考价值。
sql语句最基本就是增删改查。
软件:sqlserver2005
电脑:WIN10
系统:ISO
1、点击management studio,连接到你的数据库。
2、在你要操作的数据库点击右键--新建查询。
3、插入语句,在右侧输入命令,执行,如图3。
4、删除语句,我们把刚刚添加的删除,在右侧输入命令,执行,如图4。
5、修改语句,在右侧输入命令,查询一下看是不是改了。
参考技术A1、数据库增加数据:
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语句大全
sql语句的增删改查
要语句并注解
下面教大家sql增删改查语句怎么写,操作方法如下。
1、首先在电脑中打开navicat,点击新建查询。
2、然后在打开的软件中,写出insert语句增加数据。
3、接着用delete语句删除数据。
4、最后写出update语句对数据进行修改,用select语句对数据进行查询,这样就完成了。
参考技术A 4、说明:创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根据已有的表创建新表:
A:create table tab_new like tab_old (使用旧表创建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
5、说明:删除新表
drop table tabname
6、说明:增加一个列
Alter table tabname add column col type
注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。
7、说明:添加主键: Alter table tabname add primary key(col)
说明:删除主键: Alter table tabname drop primary key(col)
8、说明:创建索引:create [unique] index idxname on tabname(col….)
删除索引:drop index idxname on tabname
注:索引是不可更改的,想更改必须删除重新建。
9、说明:创建视图:create view viewname as select statement
删除视图:drop view viewname
10、说明:几个简单的基本的sql语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串)---like的语法很精妙,查资料!
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]本回答被提问者采纳 参考技术B 添加:
insert
into
table(a,b)
vlaue(111,222);
删除:
delete
from
table
where
id=1;
改:
update
table
set
a
=
333
where
id=2;
查:
select
*
from
table
where
id=4; 参考技术C
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语句大全
参考技术D 楼上的很全,不错的以上是关于增删改查sql语句的主要内容,如果未能解决你的问题,请参考以下文章