create database 创建数据库

alter database 修改数据库

create table 创建新表

alter table 改变数据库表

drop table 删除表

create index 创建索引

drop index 删除索引


select从表中选取数据:

select 列名称1,列名称2 from 表名称

select * from 表名称 (*:选取所有列的快捷方式)

select distinct 列名称 from 表名称 distinct用于返回唯一不同的值


where 如需有条件的从表中选取数据,可将wehere子句添加到select语句。

语法:select 列名称 from 表名称 where 列 运算符 值

select *from Persons where City='Beijing' 选取居住在城市 "Beijing" 中的人

SQL 使用单引号来环绕文本值(大部分数据库系统也接受双引号)。如果是数值,请不要使用引号。


and 和or运算符

AND 和 OR 可在 WHERE 子语句中把两个或多个条件结合起来。

如果第一个条件和第二个条件都成立,则 AND 运算符显示一条记录。

如果第一个条件和第二个条件中只要有一个成立,则 OR 运算符显示一条记录。


select * from Persons where FristName='chen' and LastName='na'

结合使用:

select * from persons where (FristName='chen' or FristName='li') and LastName='na'


order by:用于根据指定的咧对结果集进行排序。(默认为升序排列,如果按照降序对记录进行排序,可以使用 DESC 关键字

sql 基础(一)

sql 基础(一)

以逆字母顺序显示公司名称:

select Company,OrderNumber from Orders order by Company DESC

以逆字母顺序显示公司名称,并以数字顺序显示顺序号:

select Company,OrderNumber form Orders orders order by Company DESC,Order number ASC

insert into 像表格中插入行

语法:insert into 表名称 values (值1,值2,...)

也可以指定索要插入数据的列:

insert into table_name (列1,列2,...) value (值1,值2,...)


update 修改表中的数据

语法: update 表名称 set 列名称 = 新值 where 列名称 = 某值

为 lastname 是 "na" 的人添加 firstname:

update Person set FirstName = 'chen' where lastName = 'na'

更新某一行的若干列:

sql 基础(一)

delete 删除表中的行

语法: delete form 表名称 where 列名称 = 值

delete form Person where LastName = 'wilson'

sql 基础(一)

删除所有行:

delete from 表名称   或   delete * from 表名称

相关文章:

  • 2021-09-15
  • 2022-01-21
  • 2021-08-30
  • 2021-09-01
  • 2021-12-19
  • 2021-10-18
猜你喜欢
  • 2021-05-20
  • 2021-05-25
  • 2022-01-08
  • 2022-01-19
  • 2021-12-23
  • 2021-11-06
  • 2017-12-05
相关资源
相似解决方案