-1

I trying the 'create view' to store data for later visualizations but it gives me an error:

Create View PercentPopulationVaccinated as
select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations,
SUM(Cast(vac.new_vaccinations as bigint)) OVER (Partition by dea.location order by dea.location,
dea.date) as RollingPeopleVaccinated
--- , (RollingPeopleVaccinated/population)*100
From PortfolioProject..CovidVaccinations vac
Join PortfolioProject..CovidDeaths dea
    On dea.location = vac.location 
    and dea.date = vac.date
Where dea.continent is not null`

The error says: There is already an object named 'PercentPopulationVaccinated' in the database.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • 1
    Does this answer your question? [Temporary table in SQL server causing ' There is already an object named' error](https://stackoverflow.com/questions/18321245/temporary-table-in-sql-server-causing-there-is-already-an-object-named-error) – qorka Apr 06 '22 at 20:41
  • If you post images of code or error messages, please also copy/paste or type the actual code/message directly into the post. While images and screenshots can be helpful for providing context, the post should still be clear and useful without them. Please see [Why may I not upload images of code on SO when asking a question?](//meta.stackoverflow.com/a/285557/208273)—the same reasoning applies to error messages as well. Posts in which essential text is only included in images are likely to be closed for not having enough details. – Ryan M Apr 06 '22 at 20:44
  • 1
    The view already exists. You want `CREATE OR ALTER` if the view already exists and you want to update or replace it. – Edward Radcliffe Apr 06 '22 at 20:47
  • Try change the `view` name, seems the name is available already. You can add `view` at the back of the name. – Ibrahim Hammed Apr 06 '22 at 20:47

1 Answers1

0

To overwrite an existing view use

Create or Alter View . . .
David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • Thanks David! Now the problem is that when I click on the View tab, and I refresh it, the table doesn't appear below system views. It should be there but for some reason it isn't. Do you know why? I'll appreciate it! – Brian Anderson Apr 06 '22 at 21:11