搜集SQL常用的操作语句
2022-12-11 · 百度认证:北京惠企网络技术有限公司官方账号
结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言,是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
一、插入(复制)表数据
1、INSERT INTO 语句:
(1)插入新的一行数
[sql] view plain copy;
INSERT INTO Persons VALUES ('Gates', 'Bill', 'Xuanwumen 10', 'Beijing');
(2)在指定的列中插入数据
[sql] view plain copy;
INSERT INTO Persons (LastName, Address) VALUES ('Wilson', 'Champs-Elysees');
2、SQL SELECT INTO 语句可用于创建表的备份复件
(1)在建表时复制所有数据
[sql] view plain copy;
create table userinfo_new as select * from userinfo;
(2)在建表时复制部分数据
[sql] view plain copy;
create table userinfo_new1 as select id,username from userinfo;
(3)在添加时复制所有数据
[sql] view plain copy;
insert into userinfo_new select * from userinfo;
(4)在添加时复制部分数据
[sql] view plain copy;
insert into userinfo_new(id,username) select id,username from userinfo;
二、修改表数据
Update 语句
(1)无条件更新
[sql] view plain copy;
update userinfo set userpwd='111',email='111@126.com';
(2)有条件更新
[sql] view plain copy;
update userinfo set userpwd='123456' where username='xxx';
三、删除表数据
1、DELETE 语句
(1)无条件删除
[sql] view plain copy;
dalete from userinfo;
(2)有条件删除
[sql] view plain copy;
delete from userinfo where username='yyy';
四、查询表数据
1、SELECT 语句:
(1)查询所有字段
[sql] view plain copy;
select * from users;
(2)查询指定字段
[sql] view plain copy;
select username,salary from users;
2、SELECT DISTINCT 语句
从 Company" 列中仅选取唯一不同的值,需要使用 SELECT DISTINCT 语句:
[sql] view plain copy;
SELECT DISTINCT Company FROM Orders;