SQL基础学习(一)

来源:互联网 发布:google python style 编辑:程序博客网 时间:2024/05/17 07:45

一.SQL的定义:

      SQL指结构化查询语言,让我们可以对数据库进行访问,市一中ANSI的标准计算机语言。


二.SQL的语句简析:

    1.查询语句:

         select 列名称 from 表名称 (查询某一列数据)

         select * from 表名称 (查询表的所有内容)


     2.去除重复值:select distinct  列名称 from 表名称 

select distinct  Name from Persons;

     3.查询条件:  

      select 列名称 from 表名称 where 列  运算符  值 (select * from Persons where City= ‘beijng’;)

select * from Persons where City= 'beijng';

     4.and 和 or 运算符的运用

      and 和 or 可在where 子语句中那两个或多个条件结合起来。

select * from Persons where FirstName = '李' and LastName = '明';

select * from Persons where (FirstName='Thomas' or FirstName='William') and LastName='Carter';

   5.order by语句

     order by 语句用于根据指定列对结果集进行排序,order by 默认按照升序对记录进行排序,降序使用 desc 关键字

select Company, OrderNumber from Orders order by  Company desc;

   

   6.插入语句

    insert into 语句用于向表格中插入新的行。

INSERT INTO 表名称 VALUES (值1, 值2,....)

  指定所要插入数据的列:

INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)

   

   7.更新语句

    update用于修改表中的数据

    update 表名称  set 列名称  = 新值 where 列名称 = 某值

update Person set Address = 'Zhongshan 23', City = 'Nanjing' where LastName = 'Wilson'

   8.删除数据

   delete 语句用于删除表中的行

   delete from 表名称 where 列名称 = 值

delete from Person where LastName = 'Wilson';






0 0
原创粉丝点击