public function deleteTable($tablename) {

        $table = $this->getTable($tablename);
        if ($table) {
            $i = $this->findTableInArray($tablename);
            // Look for prev and next table
            $prevtable = $this->getTable($table->getPrevious());
            $nexttable = $this->getTable($table->getNext());
            // Change their previous and next attributes
            if ($prevtable) {
                $prevtable->setNext($table->getNext());
            }
            if ($nexttable) {
                $nexttable->setPrevious($table->getPrevious());
            }
            // Delete the table
            unset($this->tables[$i]);
            // Reorder the tables
            $this->orderTables($this->tables);
            // Recalculate the hash
            $this->calculateHash(true);
            // We have one deleted table, so the structure has changed
            $this->setVersion(userdate(time(), '%Y%m%d', 99, false));
            $this->setChanged(true);
        }
    }