create table T_Employee(FNumber VARCHAR(20),FName VARCHAR(20),FAge INT,FSalary NUMERIC(10,2),PRIMARY KEY(FNumber));
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*DEV001*,*Tom*,25,8300);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*DEV002*,*Jerry*,28,2300.80);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE001*,*John*,23,5000);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE002*,*Kerry*,28,6200);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE003*,*Stone*,22,1200);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*HR001*,*Jane*,25,2200.88);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*HR002*,*Tina*,25,5200.36);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*IT001*,*Smith*,28,3900);
INSERT INTO T_Employee(FNumber,FAge,FSalary)VALUES(*IT002*,27,2800);
---------Lesson7抑制重复数据
alter table T_Employee add FSubCompany varchar(20); --分公司
alter table T_Employee add FDepartment varchar(20); --部门
alter table T_Employee add FInDate datetime; --入职日期
update T_Employee set FInDate=*2010-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*development*where FNumber=*DEV001*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*development*where FNumber=*DEV002*;
update T_Employee set FInDate=*2012-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*HumanResource*where FNumber=*HR001*;
update T_Employee set FInDate=*2009-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*HumanResource*where FNumber=*HR002*;
update T_Employee set FInDate=*2010-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*InfoTech*where FNumber=*IT001*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*InfoTech*where FNumber=*IT002*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*Sales*where FNumber=*SALE001*;
update T_Employee set FInDate=*2012-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*Sales*where FNumber=*SALE002*;
update T_Employee set FInDate=*2009-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*Sales*where FNumber=*SALE003*;
-----------建立临时工表
create table TempEmployee(FIdCardNumber varchar(20),FName varchar(20),FAge int not null,PRIMARY KEY(FIdCardNumber));
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890121*,*Sarani*,20);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890122*,*Tom*,24);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890123*,*YaLaHa*,18);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890124*,*Tina*,26);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890125*,*Konkaya*,30);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890126*,*Fotifa*,27);
----------------最后一讲 Join
CREATE TABLE [T_Customers](
[ID] [INT] NOT NULL,
[NAME][NVARCHAR](50) COLLATE Chinese_PRC_CI_AS Null,
[Age][int] null
);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(1,N*tom*,10);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(2,N*jerry*,15);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(3,N*john*,22);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(4,N*lily*,18);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(5,N*lucy*,18);
CREATE TABLE[T_Orders](
[ID][int] NOT NULL,
[BillNo][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[CustomerId] [int] NULL
);
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(1,N*001*,1)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(2,N*002*,1)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(3,N*003*,3)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(4,N*004*,2)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(5,N*005*,2)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(6,N*006*,5)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(7,N*007*,4)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(8,N*008*,5)
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*DEV001*,*Tom*,25,8300);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*DEV002*,*Jerry*,28,2300.80);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE001*,*John*,23,5000);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE002*,*Kerry*,28,6200);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*SALE003*,*Stone*,22,1200);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*HR001*,*Jane*,25,2200.88);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*HR002*,*Tina*,25,5200.36);
INSERT INTO T_Employee(FNumber,FName,FAge,FSalary)VALUES(*IT001*,*Smith*,28,3900);
INSERT INTO T_Employee(FNumber,FAge,FSalary)VALUES(*IT002*,27,2800);
---------Lesson7抑制重复数据
alter table T_Employee add FSubCompany varchar(20); --分公司
alter table T_Employee add FDepartment varchar(20); --部门
alter table T_Employee add FInDate datetime; --入职日期
update T_Employee set FInDate=*2010-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*development*where FNumber=*DEV001*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*development*where FNumber=*DEV002*;
update T_Employee set FInDate=*2012-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*HumanResource*where FNumber=*HR001*;
update T_Employee set FInDate=*2009-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*HumanResource*where FNumber=*HR002*;
update T_Employee set FInDate=*2010-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*InfoTech*where FNumber=*IT001*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*InfoTech*where FNumber=*IT002*;
update T_Employee set FInDate=*2011-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*Sales*where FNumber=*SALE001*;
update T_Employee set FInDate=*2012-09-07 12:00:00*, FSubCompany=*Shenzhen*,FDepartment=*Sales*where FNumber=*SALE002*;
update T_Employee set FInDate=*2009-09-07 12:00:00*, FSubCompany=*Beijing*,FDepartment=*Sales*where FNumber=*SALE003*;
-----------建立临时工表
create table TempEmployee(FIdCardNumber varchar(20),FName varchar(20),FAge int not null,PRIMARY KEY(FIdCardNumber));
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890121*,*Sarani*,20);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890122*,*Tom*,24);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890123*,*YaLaHa*,18);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890124*,*Tina*,26);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890125*,*Konkaya*,30);
insert into TempEmployee(FIdCardNumber,FName,FAge)values(*1234567890126*,*Fotifa*,27);
----------------最后一讲 Join
CREATE TABLE [T_Customers](
[ID] [INT] NOT NULL,
[NAME][NVARCHAR](50) COLLATE Chinese_PRC_CI_AS Null,
[Age][int] null
);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(1,N*tom*,10);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(2,N*jerry*,15);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(3,N*john*,22);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(4,N*lily*,18);
INSERT INTO [T_Customers]([ID],[NAME],[Age])VALUES(5,N*lucy*,18);
CREATE TABLE[T_Orders](
[ID][int] NOT NULL,
[BillNo][nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[CustomerId] [int] NULL
);
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(1,N*001*,1)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(2,N*002*,1)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(3,N*003*,3)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(4,N*004*,2)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(5,N*005*,2)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(6,N*006*,5)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(7,N*007*,4)
INSERT INTO [T_Orders]([ID],[BillNo],[CustomerId])VALUES(8,N*008*,5)