1 / 7

一阶段: About SQL

一阶段: About SQL. SQL has 3 struct models ,inner model( includes Stored file ) ,outer model(includes view) and model(includes base table).

chynna
Download Presentation

一阶段: About SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 一阶段:About SQL • SQL has 3 struct models ,inner model( includes Stored file ) ,outer model(includes view) and model(includes base table). • SQL有3个模式,内模式(存储文件),外模式(包括视图)和模式(包括基本表)base table existed in the database .A base table have a Stored file.but a base table may has many indexs which also stored in the Stored file. • 一个表只对应一个存储文件,但可以对应多个索引。索引也存在存储文件中。 • However view isn’t existed in the database .it is derived from the base table .so ,we can say it is just a invisival table. • 视图不独立存在于数据库中,是从基本表导出来的,可以说它是一个虚表。

  2. For example ,if hava two tables like these

  3. 第三阶段:举例子 This is the view If you had created a view,And if you want to select informations from the tables ,you can easily get the information throught the views. 如果你已经定义了一个视图,你可以通过视图很容易的得到你想查询的信息,如右图: SELECT * FROM cardInfo WHERE (DATEDIFF(Day,getDate(),openDate)<DATEPART(weekday,openDate)) SELECT DISTINCT cardID FROM transInfo WHERE transMoney=(SELECT Max(transMoney) FROM transInfo) SELECT customerName as 客户姓名,telephone as 联系电话 FROM userInfo WHERE customerID IN (SELECT customerID FROM cardInfo WHERE IsReportLoss=1) SELECT,.., FROM userInfo INNER JOIN cardInfo ON userInfo.customerID =cardInfo.customerID WHERE balance<200

  4. 第四阶段:展示如何建立课本第82页中的3个表 一 建Student表 二 增加表主键约束PK_Sno Create table [dbo].[Student] [Sno] [nchar] (20) not null, [Sname] [nchar] (20) not null, [Ssex] [nchar] (20) not null, [Sage] [int] (20) not null, [Sdept] [nvarchar] (20) not null, Alter table [dbo].[Student] Add Constraint PK_Sno Pramiry key (Sno)

  5. 一 建Course表 二 增加表主键约束PK_Sno Create table [dbo].[Course] [Cno] [nchar] (20) not null, [Cname] [nchar] (20) not null, [Cpno] [nchar] (20) not null, [Ccredit] [int] (20) not null, Alter table [dbo].[Student] Add Constraint PK_Sno Pramiry key (Cno)

  6. 二 增加表外键约束 一 建SC表 Alter table [dbo].[Student] Add Constraint FK_Cno Foreign key (Cno) References Course( Cno )Add Constraint FK_SnoForeign key (Sno)References Student(Sno) Create table [dbo].[SC] [Cno] [nchar] (20) not null, [Sno] [nchar] (20) not null, [Grade] [int] (20) not null,

  7. My speech is over. Thank you !!

More Related