sql 部分知识回顾

//表备份
select * into Persons in ‘back.mdb’ from Persons;

//创建新表存储两张表的结果集
select Persons.LastName, Orders.OrderNo
into Persons_order_backup
from Persons
inner join Orders
on Persons.Id = Orders.Id_p;

create database test;
create table (column_name, type);
//decimal numeric 小数

unique//唯一性 约束
//多列约束
constraint uc_PersonID unique (id, LastName);

alter table Persons add unique(id);

alter table Persons
add constraint uc_PersonID unique(id, LastName);

alter table Persons drop index uc_PersonID;

alter table Persons add primary key(id);

alter table Persons drop primary key;

foreign key; //外键约束, 1,预防破环表之间连接的动作 2,防止非法数据插入外键列,因为它必须是指向的那个表中的值之一

foreign key (id_p) references Persons(id_p);

alter table Orders add foreign key (id_p) references Persons(ID_P);

alter table Orders drop foreign key fk_perOrders

check 限制列中值的范围
check(id > 0)

default

alter table Persons alter COLUMN city drop default

alter table Persons alter column city set default ‘123’;

create unique index index_name on table (column_name)

drop index index_name on table table_name;

truncate table table_name

alter table table_name add column_name datatype;

alter table table_name alter column column_name year

alter table table_name drop column column_name;

create view view_name as select column_name from table_name where condition;

create view [current product list] as
select productId, productName from Product where Discontinued = No;
//创建视图
create view [products above average price] as
select productName, unitPrice from Products where unitPrice > (select avg(unitPrice) from products);
//创建的视图
create view [Category Sales For 1997] as
select DISTINCT CategoryName, sum()

delete from socre where id not in
(select mid from(select min(id) as mid from score group by name, kecheng, fenshu)
as b);

select a.* from testdb as a, (select occmonth, max(debitOccur) as debit101 from testdb where accid = ‘101’ group by occmonth) as b where

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值