文档详情

c#之数据库简介.ppt

发布:2015-08-12约7.23千字共45页下载文档
文本预览下载声明
数据库关联映射建表图示 一对一:班级和班号,学生姓名和学号--一个表,一个主键一条信息 一对多:班级和学生,学校和学校中的院系--两个表,A主表每条信息在B次表中有多条子分类对应 多对多:学生和课程,教师和学生 ---A表一个主键 B表一个主键 C关系表中一条信息记录两个表的id以示关系。 数据表间一对多关系如下图: 关联映射:多对多 SELECT 查询 一、 简单查询 简单的Transact-SQL查询只包括选择列表、FROM子句和WHERE子句。它们分别说明所查询列、查询的 表或视图、以及搜索条件等。 例如: 1、选择所有列: select * from FriendTable 2、选择部分列: 3、更改列标题:SELECT 昵称=nickname,电子邮件=email FROM testtable 4、删除重复行:ELECT语句中使用ALL或DISTINCT选项来显示表中符合条件的所有行或删除其中重复的数据行,默认 为ALL。 5、限制返回的行数:代码:SELECT TOP 2 * FROM `testtable` 代码:SELECT TOP 20 PERCENT * FROM `testtable` SELECT 查询 (二) FROM子句 --select * from friendtable,userinformation --select * from friendtable,userinformation whereuserinformation.id=friendtable.userid --select * from (select top 2 * from userinformation) as a, (select top 10 * from friendtable) as b where a.id =b.userid 三、 SELECT 查询 --select ALL id from userinformation union select friendid from friendtable --select ALL id from userinformation union all select ALL friendid from friendtable 四:SELECT 查询 -等值连 --select * from userinformation as a inner join friendtable as b on a.id =b.userid --不等值连 --select * from userinformation as a inner join friendtable as b on a.id !=b.userid --自然连 --select a.id,a.pwd,a.userstate,a.userip,b.friendid from userinformation as a inner join friendtable as b on a.id =b.userid --左外连 --select * from userinformation as a left join friendtable as b on a.id =b.userid --右外连 --select * from userinformation as a right join friendtable as b on a.id =b.userid --全外连 --select * from userinformation as a full join friendtable as b on a.id =b.userid --交叉连接 select * from userinformation as a cross join friendtable as b 存储过程 一:带输出参数存储过程 ALTER PROCEDURE [dbo].[GetUserNameProcedure] @userid nchar(8), @userName nchar(50) output AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; select @userName =username from userinformation where id =@userid -- Insert statements for procedure here END 存储过程 二:
显示全部
相似文档