 
                    
                
         
    
    
    
	
	
		
    
    
        
            
            
            
                    
        
         
     
    
 select * from tdx_order t inner join [Tdx_Safety] s on t.id = s.[OrderId]
- ---
 
 
- if exists(select [id] from sysobjects where name='student')  
-     drop table student  
- go  
-   
- create table student  
- (  
-     sname varchar(20) not null,  
-     sclass varchar(20) not null  
- )  
- go  
-   
- alter table student add constraint pk_student primary key(sname,sclass);  
- go  
-   
- if exists(select [id] from sysobjects where name='score')  
-     drop table score  
- go  
-   
- create table score  
- (  
-     scoreid int not null primary key identity(1,1),  
-     sname varchar(20) not null,  
-     sclass varchar(20) not null,  
-     score float  
- )  
- go  
-   
- alter table score add constraint fk_score foreign key(sname,sclass) references student(sname,sclass);  
- go  
-   
- insert into student values('aaa','1');  
- insert into student values('ccc','2');  
- insert into student values('bbb','2');  
- insert into student values('ddd','2');  
- insert into student values('ccc','3');  
- insert into student values('ddd','4');  
-   
- insert into score(sname,sclass,score) values('aaa',1,66);  
- insert into score(sname,sclass,score) values('bbb',2,77);  
- insert into score(sname,sclass,score) values('ccc',2,88);  
- insert into score(sname,sclass,score) values('ddd',4,99);  
-   
- /*  
- --外键插入null值  
- insert into score(score) values(66);  
- insert into score(score) values(77);  
- insert into score(score) values(77);  
- */  
-   
- select * from student;  
- select * from score;  
-   
- --复合主键内连接  
- select * from student t inner join score s on t.sname = s.sname and t.sclass = s.sclass;  
-   
- --复合主键左外连接  
- select t.sname,t.sclass from student t left outer join score s on t.sname = s.sname and t.sc 
 
             
            posted @ 
2008-10-28 12:40 
window5549-accp 
阅读(
524) 
评论() 
 
收藏 
举报