sql cheat sheet

CREATE DATABASE DATA_NAME
drop database database_name


create table person
(
lastname varchar,
firstname varchar,
address varchar,
age int
)


alter tale table_name add column_name data_type
alter table table_name ddrop column_name datatype
drop table table_name


create index person_index
on person ( lastname, firstname )

creaete unique indeix personindex
on person( lastname desc )

drop index person personindex

insert into persons values ( 'hussein', 'saddam', ' white house' )
insert into persons( lastname, firstname, address )
values ( 'hussein', 'saddam', 'white house' )

update person set address = 'ups' whwere last name = 'hussein'


delete from person where lastname = 'hussein'

truncate table person

select lastname,firstname from persons
select * from persons
select distincet lastname,firstname from persons
select * from persons where sex='female'
select * from persons where year > 1970
select * from persons where firstname = 'saddam' and lastname = 'hussein'
select * from persons where firstname = 'saddam' or lastname = 'hussein'

select * from persons where ( firstname = 'tove' or firstname = 'stephen' )
and lastname = 'swendson'

select * from persons where firstname like '0%'
select * from persons where firstname like '%a'
select * from persons where firstname like '%1a%'

select * from persons where lastname in ( 'hansen', 'pettersen' )

select * from persons order by lastname
select firstname, lastname f rom persons order by lastname desc

select company, ordernumber from orders order by company
desc, ordernumber asc

select company, sum( amount) from sales group by company


select company, sum( amount ) from sales group by company having sum( amount ) > 1000

select lastname as family, firstname as name from persons
select lastname,firstname from person as employees


select employees.name, orders.product from employees inner join orders
on employees.employee_id = order.employee_id

select empoyees.name, orders.product from employees left join orders
on empoyees.employee_id = orders.employee_id

select employees.name, orders.product from employees right join ordoers on employees.employee_id = orders.employee_id


select e_name from employees_norway union
select e_name from employees_usa

select e_name from empoyees_norway
union all
select e_name from employees_usa


select * into persons_backup from persons
select person.* into persons in 'backup.db' from persons where city='sandnes'

create view [current product list] as select productid, productname from products where discontinued = no


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值