mssql paging 방법론

Posted by MD워시퍼
2012. 8. 19. 18:25 Study/MS-SQL
728x90

USE [3SforU_DB]
GO
/****** Object:  StoredProcedure [dbo].[sp_Circle_Activity_listw]    Script Date: 08/19/2012 17:40:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[sp_TPMBoard_listw]
@Kind_Code        nvarchar(40),
@BBS_Title        nvarchar(400),
@BBS_Type        nvarchar(40),
@BBS_Contents    nvarchar(40),
@User_ID        nvarchar(40),
@page_num        int,
@current_num    int
AS
 
   SELECT TOP (@page_num * 1) *
     FROM TPMBoard
    Where BBS_Seq not in (SELECT TOP ((@current_num - 1) * @page_num) BBS_Seq
                            FROM TPMBoard
                           WHERE (@BBS_Title is null or @BBS_Title = '' or BBS_Title like '%' + @BBS_Title + '%')
                             and (@BBS_Type is null or @BBS_Type = '' or BBS_Type like @BBS_Type)
                             and (@BBS_Contents is null or @BBS_Contents = '' or BBS_Contents like '%' + @BBS_Contents + '%')
                             and (@User_ID is null or @User_ID = '' or User_ID like @User_ID)
                             and Kind_Code = @Kind_Code
                           order by BBS_Seq DESC)
      AND (@BBS_Title is null or @BBS_Title = '' or BBS_Title like '%' + @BBS_Title + '%')
     and (@BBS_Type is null or @BBS_Type = '' or BBS_Type like @BBS_Type)
     and (@BBS_Contents is null or @BBS_Contents = '' or BBS_Contents like '%' + @BBS_Contents + '%')
     and (@User_ID is null or @User_ID = '' or User_ID like @User_ID)
     and Kind_Code = @Kind_Code
    order by BBS_Seq DESC

MSSQL 데이터베이스에서 순번, 칼럼코드, 칼럼명, 타입, IS NULL 까지 조회할 수 있는 쿼리

Posted by MD워시퍼
2012. 8. 5. 11:32 Study/MS-SQL
728x90
SELECT b.column_id AS COLUMN_ID

      , b.name AS COLUMN_NAME
      , c.value AS DESCRIPTION
      , CASE WHEN d.CHARACTER_MAXIMUM_LENGTH > 0 THEN d.DATA_TYPE + '(' + CAST(d.CHARACTER_MAXIMUM_LENGTH as VARCHAR)+ ')' ELSE d.DATA_TYPE END
      , d.IS_NULLABLE
      , a.name AS TABLE_NAME
   FROM sys.objects a
    LEFT JOIN sys.columns b ON a.object_id=b.object_id
    LEFT JOIN sys.extended_properties c ON (a.object_id=c.major_id AND b.column_id=c.minor_id)
    LEFT JOIN INFORMATION_SCHEMA.COLUMNS d ON (a.name=d.TABLE_NAME AND b.name=d.COLUMN_NAME)
   ORDER BY a.name, b.column_id;


DB 설계서 제작시 유용함(농심 프로젝트시에 사용함)

[MS-SQL] 테이블의 컬럼 설명까지 보여주는 쿼리

Posted by MD워시퍼
2011. 9. 2. 00:01 Study/MS-SQL
728x90
SELECT  
   [Table Name] = OBJECT_NAME(c.object_id), 
   [Column Name] = c.name, 
   [Description] = ex.value  
FROM  
   sys.columns c  
LEFT OUTER JOIN  
   sys.extended_properties ex  
ON  
   ex.major_id = c.object_id 
   AND ex.minor_id = c.column_id  
   AND ex.name = 'MS_Description'
WHERE  
   OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
   AND OBJECT_NAME(c.object_id) = '<<Table_Name>>' 
ORDER  
   BY OBJECT_NAME(c.object_id), c.column_id 

MS-SQL 관련 프로시저 및 TABLE 보는 것들(아직 정리안된 것)

Posted by MD워시퍼
2011. 7. 23. 14:11 Study/MS-SQL
728x90
select name , create_date, modify_date
  from sys.objects
where type = 'P'
  AND create_date >  DATEAdd(dd, -70, GETDATE())

select * from INFORMATION_SCHEMA.PARAMETERS

sp_stored_procedures ST_LM_DMD_DEMAND_BREAKDOWN_FIXED_UPDATE

sp_help

sp_helptext