--
TODO LIST 용테이블생성
Create Table Items
(
ID Int Identity(1, 1) Primary Key, --일련번호
[Description]
VarChar(8000) Not Null, --설명
Opened DateTime Default(GetDate()), --등록일
Closed DateTime Null, --완료일
Priority TinyInt Default(1) --우선순위(1:높음,2:보통,3:낮음)
)
Go
--Drop
Table Items
--6가지예시문: 입력, 출력, 상세, 수정, 삭제, 검색
Insert Into Items([Description], Priority)
Values('먹고', 1 )
Insert Into Items([Description], Priority)
Values('게임하고', 2)
Insert Into Items([Description], Priority)
Values('자야지', 3)
Go
Select [Description], Opened, Closed, Priority
From Items
Go
Select * From Items Where Priority = 1
Go
Update Items Set [Description] = '씻어야징'
Where Priority
= 1
Go
Delete From Items Where [Description] = '자야지'
Go
Select * From Items Where [Description] Like '%게임%'
Go
--저장프로시저
Create Procedure
AddItems
@Description
VarChar(8000),
@Priority
TinyInt
As
Insert Into Items(Description, Priority)
Values(@Description, @Priority)
Go
AddItems '밥먹고나서', 2
AddItems '게임해야지!', 1
Create Proc GetItems
As
Select * From Items Order By ID Asc
Go
GetItems
Create Proc GetItemsByPriority
@Priority
TinyInt
As
Select * From Items
Where Priority = @Priority
Go
GetItemsByPriority 1
Create Proc UpdateItems
@Description
VarChar(8000),
@Priority
TinyInt,
@Opened DateTime,
@Closed DateTime,
@ID Int
As
Update Items
Set [Description] = @Description,
Priority
= @Priority,
Opened
= @Opened,
Closed
= @Closed
Where
ID = @ID
Go
Create Proc DeleteItems
@ID Int
As
Delete From Items Where ID = @ID
Go
DeleteItems 2
Create Proc SearchItems
@SearchText
VarChar(50)
As
Declare @Sql VarChar(500)
Set @Sql =
'Select * From
Items
Where Description Like ''%'
+ @SearchText + '%'''
Exec(@Sql)
Go
SearchItems '게임'
'DataBase > MS SQL' 카테고리의 다른 글
MS-SQL 프로시저에서 If문 말고 다른거 써보자 (0) | 2010.06.17 |
---|---|
48.MS_SQL 2008 - Trigger ( 트리거 ) (0) | 2009.10.01 |
46.MS_SQL 2008 - 도시락 주문프로그램 - 최종 (0) | 2009.09.21 |
45.MS_SQL 2008 - 도시락 주문 테이블 (0) | 2009.09.21 |
44.MS_SQL 2008 - 트랜잭션( Tranjection ) (0) | 2009.09.18 |
Comments