DataBase/MS SQL

25.MS_SQL 2008 - Join_Left(조인문) [1]

Godffs 2009. 9. 14. 14:22
반응형

카테고리 상품 테이블을 설계 후 Join Lift 조인문을 이용한 예제입니다.


--[tempdb]

--조인(Join) : Left 조인

--카테고리테이블설계

Create Table dbo.Categories

(

       CategoryID Int Identity(1, 1) Not Null Primary Key, --카테고리번호

       CategoryName VarChar(25) Not Null

)

Go

Insert Categories Values('가전')

go

Insert Categories Values('컴퓨터')

go

Insert Categories Values('서적')

go

 

--상품테이블설계

Create Table dbo.Products

(

       ProductID Int Identity(1, 1) Not Null Primary Key, --상품고유번호

       ModelName VarChar(25) Not Null,                                --상품명

       SellPrice Int Null,                                                  --가격

       CategoryID Int Null                                                  --카테고리(1,2,3)

)

Go

  

--상품명(코멘트) 테이블설계
Create Table dbo.Reviews

(

       ReviewID Int Identity(1, 1) Primary Key, --일년번호

       ProductID Int References Products(ProductID), --외래키

       Comment VarChar(3850)

)

Go

Insert Into Reviews Values(1, '냉장실에서얼음이얼어요...') --냉장고제품에코맨트작성

Insert Into Reviews Values(2, '브랜드가모닝글로리') --노트북제품에코맨트작성

  

select *From  Categories

select *From Products



반응형