블로그 이미지
따시쿵

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2014. 7. 22. 11:59 잡동사니

1 ÷ 0은 전산을 하는 사람들은 에러 처리를 한다.

초기 개발시에는 위 문제를 간과해서 에러가 발생하는 빈도수가 많았지만 작업을 할 수록 습관적으로 예외처리를 한다.

그런데 왜 1 ÷ 0 은 안 되는지에 궁금해서 자료를 찾아 보니 다음과 같은 이유로 문제가 발생하는군요.

1. 1 ÷ 0 는 나눗셈, 곱셈 법칙에 위배 된다.

a ÷ b = c 란 표현은 a = b  x c 란 표현으로 바뀌쓸수 있다. 예를 들어서 5 / 2 = 2.5 로 5 = 2.5 x 2 인 경우와 같다. 그럼 1 ÷ 0 = y 란 할때 1 = 0 x y 를 만족하는 y 가 없다는 것이다. 당연히 0 에 어떤수를 곱해서 1을 만족하는 수는 없다.

2. 1 ÷ 0 는 무수히 많은 값들이 존재한다.

1 ÷ 0 를 그래프로 그리게 되면 이차원 그래프가 된다. x 축이 0 에 가까울수록 무한히 y 축으로 뻗어 나가는 형태를 띄고 있다. 즉 답의 개숫가 무한히 많다는 의미가 아닐까 싶다. 즉 답변이 너무 많아서 답을 정의할 수 없다.


'잡동사니' 카테고리의 다른 글

Syntaxhighter 설정하는 파일들  (0) 2014.07.22
posted by 따시쿵
2014. 7. 22. 11:46 MSSQL

1.  [user_id],[account_seq] 필드에서 중복행 찾기


SELECT [user_id],[account_seq], count(*) AS insertCount
FROM [dbo].[tbl_Assign]
GROUP BY [user_id],[account_seq]
HAVING count(*) > 1


2.  [user_id],[account_seq] 필드에서 가장 큰 seq 값 찾기


SELECT MAX(seq), [user_id],[account_seq], count(*) AS insertCount
FROM [dbo].[tbl_Assign]
GROUP BY [user_id],[account_seq]
HAVING count(*) > 1


3.  중복된 행 중 seq 가 가장 큰 값을 제외한 값 select


SELECT a.seq AS seq
FROM [dbo].[tbl_Assign] A 
INNER JOIN ( SELECT MAX(seq) as seq, [user_id],[account_seq], count(*) AS insertCount
		    FROM [dbo].[tbl_Assign]
		    GROUP BY [user_id],[account_seq]
                    HAVING count(*) >1 ) B
ON A.[user_id] = B.[user_id] and A.[account_seq] = B.[account_seq] and A.seq <> B.seq



4.  중복된 행 중 seq 가 가장 큰 값을 제외한 값 delete


DELETE FROM [dbo].[tbl_Assign]
WHERE seq IN (SELECT a.seq AS seq
                       FROM [dbo].[tbl_Assign] A 
                       INNER JOIN ( SELECT MAX(seq) as seq, [user_id],[account_seq], count(*) AS insertCount
                                           FROM [dbo].[tbl_Assign]
                                           GROUP BY [user_id],[account_seq]
                                           HAVING count(*) > 1) B
ON A.[user_id] = B.[user_id] and A.[account_seq] = B.[account_seq] and A.seq <> B.seq )


posted by 따시쿵
2014. 7. 22. 11:46 MSSQL



/*Perform a 'USE ' to select the database in which to run the script.*/
-- Declare variables
SET NOCOUNT ON;

DECLARE @tablename varchar(255);
DECLARE @execstr varchar(400);
DECLARE @objectid int;
DECLARE @indexid  int;
DECLARE @frag decimal;
DECLARE @maxfrag decimal;

-- Decide on the maximum fragmentation to allow for.
SELECT @maxfrag = 30.0;

-- Declare a cursor.
DECLARE tables CURSOR FOR
SELECT TABLE_SCHEMA + '.' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';

-- Create the table.
CREATE TABLE #fraglist (
                         ObjectName char(255),
			ObjectId int,
			IndexName char(255),
			IndexId int,
			Lvl int,
			CountPages int,
			CountRows int,
			MinRecSize int,
			MaxRecSize int,
			AvgRecSize int,
			ForRecCount int,
			Extents int,
			ExtentSwitches int,
			AvgFreeBytes int,
			AvgPageDensity int,
			ScanDensity decimal,
			BestCount int,
			ActualCount int,
			LogicalFrag decimal,
			ExtentFrag decimal);

-- Open the cursor.
OPEN tables;

-- Loop through all the tables in the database.
FETCH NEXT
FROM tables
INTO @tablename;

WHILE @@FETCH_STATUS = 0
BEGIN
-- Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @tablename + ''')
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS');
FETCH NEXT
FROM tables
INTO @tablename;
END;

-- Close and deallocate the cursor.
CLOSE tables;
DEALLOCATE tables;

-- Declare the cursor for the list of indexes to be defragged.
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0;

-- Open the cursor.
OPEN indexes;

-- Loop through the indexes.
FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @indexid, @frag;

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Executing DBCC INDEXDEFRAG (0, ' + RTRIM(@tablename) + ',
' + RTRIM(@indexid) + ') - fragmentation currently '
+ RTRIM(CONVERT(varchar(15),@frag)) + '%';
SELECT @execstr = 'DBCC INDEXDEFRAG (0, ' + RTRIM(@objectid) + ',
' + RTRIM(@indexid) + ')';
EXEC (@execstr);

FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @indexid, @frag;
END;

-- Close and deallocate the cursor.
CLOSE indexes;
DEALLOCATE indexes;

-- Delete the temporary table.
DROP TABLE #fraglist;
GO


posted by 따시쿵