Blog Content

    티스토리 뷰

    19.MS_SQL 2008 - SQL 테이블 추가/삭제(한 줄 메모장) [2]

    반응형

    --테이블에값추가

    Insert InTo Memos(Name, Email, Title, PostDate, PostIP)

    Values('홍길동', 'h@h.com', '안녕', Default, '127.0.0.1')

    Go

    /*

    Insert InTo Memos(Name, Email, Title) --PostDate, PostIP를입력하지않고사용해도Default로자동으로값이저장된다.

    Values('', 'h@h.com', '안녕')

    Go

    */

     

    --Num을기준으로내름차순으로정렬(높은숫자가위로)

    Select *From Memos Where 1 = 1 Order By Num Desc

     

    Update Memos Set Name = '백두산' Where Num > 0

    Delete Memos Where 1 <> 1

     

     

    --1부터100까지3의배수또는4의배수의합을구하는프로그램

    Declare @sum Int

    Declare @i Int

     

    Set @sum = 0;

     

    Set @i = 1

    While @i <=100

    Begin

           if @i % 3 = 0 Or @i % 4 = 0

           Begin

                 Set @sum = @sum + @i

           End

          

           Set @i = @i + 1

    End

     

    Select @sum

    Print @sum

    Go



    반응형

    Comments