SQL Prime number function
问题 If I have a number X and want to say IsPrime(X) = true/false using sql-server what is the best approach? Do I just import a table of primes or is there an algorithm that is fairly efficient for the smaller primes? Note: I'm not interested in numbers greater than approx. 10 million. Ended up using the following: CREATE FUNCTION [dbo].[isPrime] ( @number INT ) RETURNS VARCHAR(10) BEGIN DECLARE @retVal VARCHAR(10) = 'TRUE'; DECLARE @x INT = 1; DECLARE @y INT = 0; WHILE (@x <= @number ) BEGIN IF