I attempted to alter the URL structure of my Wordpress site. I get following error

"Fatal error: Out of memory (allocated 31981568) (tried to allocate 1111781 bytes) in ../wp-includes/wp-db.php on line 774"

I investigated in internet and that i got this solution:

1. Try adding this line to your wp-config.php file:
define('WP_MEMORY_LIMIT', '64M');

2. If you have access to your PHP.ini file, change the line in PHP.ini
If your line shows 32M try 64M:
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

3. If you don't have access to PHP.ini try adding this to an .htaccess file:
php_value memory_limit 64M

4. Talk to your host.  

Nothing labored for me personally, I didn't try the 2nd option since i have do not need php.ini file.

My Real question is why altering an simple URL cause this problem? Is due to cache or some factor?

Any help could be greatly appreciated.

WordPress needs RAM. Speak to your host and request them how your account will get and request for additional. You may have to alter hosts.