//表备份
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