Table not getting created upon activation of WP Theme


This is the code I am using to create a custom table named "prefix" + zillow--> where prefix is the wp table prefix for the site.


The actual function is given below-- it checks if such a table already exists along with assigned version number for that table(so that I can update /alter that table in a later version of this theme)--

function CreateTable() {
//Database table versions
$zillow_db_table_version= "1.0";
$table_name = $wpdb->prefix . "zillow";

$installed_ver = get_option( "zillow_db_table_version" );
//Check if the table already exists and if the table is up to date, if not create it
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name || $installed_ver != $zillow_db_table_version ) {
$sql = "CREATE TABLE " . $table_name .
" (propertyid varchar(20) NOT NULL ,
inserted_on date,
UNIQUE KEY id (id) );";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
update_option( "zillow_db_table_version", $zillow_db_table_version );
//Add database table versions to options
add_option("zillow_db_table_version", $zillow_db_table_version);


But the table is not getting created at all. What is wrong with the above code?
I tried activating the theme using above code multiple times(after first activating a different theme and then activating this one) but no table is getting created (I check directly in the WP database list of tables ).

How do I correct this?

Yours sincerely,