Simple SQL Notes


sql not case sensitive.

DML (Data Manipulation Language)

select (for querying the database)

  • select the column name from the table name
    • select LastName,FirstName from Persons
      Here Insert Picture Description
    • select * from Persons (* indicates all columns)
      Here Insert Picture Description
  • select distinct name from table column names
    • select Company from Orders
      Here Insert Picture Description
    • select distinct Company from Orders
      Here Insert Picture Description
  • Column select names from the name of the table where the value of the column operator
    operators available
    Here Insert Picture DescriptionHere Insert Picture Description
    • select * from Persons where City=‘Beijing’
      Here Insert Picture Description
  • and and or more operators based on the recording condition was filtered
    Here Insert Picture Description
    • select * from Persons where FirstName=‘Thomas’ and LastName='Carter
      Here Insert Picture Description
    • select * from Persons where FirstName=‘Thomas’ or LastName=‘Carter’
      +
    • select * from Persons where (FirstName=‘Thomas’ or FirstName=‘william’) and Lastname=‘Carter’
      Here Insert Picture Description
  • order by ordering for the result set (default ascending, descending the DESC keyword)
    Here Insert Picture Description
    • select Company, OrderNumber from Orders order by Company
      Here Insert Picture Description
    • select Company, OrderNumber from Orders order by Company, OrderNumber
      Here Insert Picture Description
    • select Company, OrderNumber from orders order by Company DESC
      +
    • select Company, OrderNumber from Orders order by Company DESC, OrderNumber ASC
      Here Insert Picture Description

insert into(用于向表格中插入新的行)

Here Insert Picture Description

  • insert into 表名称 values (值1,值2,…)
    insert into Persons values (‘Gates’, ‘Bill’, ‘Xuanwumen 10’, ‘Beijing’)
    Here Insert Picture Description
  • insert into table_name (列1,列2,…) values (值1,值2,…)
    insert into Persons (LastName, Address) values (‘Wilson’, ‘Champs-Elysees’)
    Here Insert Picture Description

update(用于修改表中的数据)

update 表名称 set 列名称 = 新值 where 列名称 = 某值
Here Insert Picture Description

  • update Person set FirstName = ‘Fred’ where LastName = ‘wilson’
    Here Insert Picture Description
  • update Person set Address = ‘Zhongshan 23’, City = ‘Nanjing’ where LastName = ‘Wilson’
    Here Insert Picture Description

delete(用于删除表中的行)

delete from 表名称 where 列名称 = 值
Here Insert Picture Description

  • delete from Person where LastName = ‘wilson’
    Here Insert Picture Description
  • 不删除表的情况下删除所有行,即表的结构、属性和索引都是完整的:
    • delete from table_name或者:
    • delete * from table_name

DDL(数据定义语言)

create database: Create a new database
alter database: modify the database
create table: Create a new table
alter table: Change database table
drop table: drop table
create index: create index
drop index: Delete Index

pending upgrade

Published 29 original articles · won praise 10 · views 7180

Guess you like

Origin blog.csdn.net/weixin_42017042/article/details/87258565