Reputation: 3176
I am trying to insert random values into a table from my linux terminal, but when i use the following SQL statement,
INSERT INTO kCreate (k1 , k2) VALUES ('$RANDOM' , '$RANDOM');
where k1 and k2 are of datatype INT, 0 is being inserted instead of a random value, What am i doing wrong here ?
Upvotes: 2
Views: 164
Reputation: 4267
k1 and k2 are of INT type, no need to put the value inside single quote, try this:
sql="INSERT into kcreate ( k1, k2) values ($RANDOM, $RANDOM);"
echo $sql | mysql -ppassword test
Upvotes: 2
Reputation: 39385
You can use rand() function of mysql with ceil(). Here is an example.
INSERT INTO kCreate (k1 , k2)
VALUES (ceil(rand()*1000) , ceil(rand()*1000));
Upvotes: 1