'How to write an update statement to update columns and check for prime numbers?

I am just learning to code SQL. Can someone help me with an update statement, I have done the insert but am stuck with an update. My table prime_test has two columns number and is_prime

Here is the question: Write one or more update statements that sets the 'is_prime' column for each associated integer. For a prime, the column should read 'prime'. For non-primes, the column should read 'composite'.

My code

    CREATE TABLE `sql_inventory`.`prime_test` (
      `number` INT NOT NULL,
      `is_prime` VARCHAR(50) NULL,
      PRIMARY KEY (`number`));

    INSERT INTO `prime`.`prime_test`
    (`number`)
    VALUES
    (rand()*(100-2+1)+2);

Function to find the prime numbers:

CREATE FUNCTION isPrime(@num int)
RETURNS VARCHAR(50)
BEGIN
    DECLARE @prime_or_notPrime INT
    DECLARE @counter INT
    DECLARE @retVal VARCHAR(50)
    SET @retVal = 'composite'
    SET @prime_or_notPrime = 1
    SET @counter = 2
    WHILE (@counter <= @number/2 )
    BEGIN
        IF (( @number % @counter) = 0 )
        BEGIN
            set @prime_or_notPrime = 0
            BREAK
        END

        IF (@prime_or_notPrime = 1 )
        BEGIN
            SET @retVal = 'prime'
        END
        SET @counter = @counter + 1
    END
    return @retVal
END
update prime_test 
set is_prime = dbo.isPrime(select number From 'prime'.'prime_test')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source