SagiLow
SagiLow

Reputation: 6029

Table X already exists using Create view X as - MySql

I'm doing :

create view WritersCouples as
select researcher.serial_number as S1, researcher.firstname as S2
from researcher, researcher as rs
where researcher.serial_number <> rs.serial_number;

And i'm getting the following error :

Error Code: 1050. Table 'WritersCouples' already exists

I'm using workbench over mySql

Thank you !

Upvotes: 1

Views: 2918

Answers (3)

bonCodigo
bonCodigo

Reputation: 14361

Add the following:

create or replace view myview
as
select ....

Upvotes: 4

BellevueBob
BellevueBob

Reputation: 9618

If the view already exists, add the OR REPLACE clause:

create OR REPLACE view WritersCouples as
select researcher.serial_number as S1, researcher.firstname as S2
from researcher, researcher as rs
where researcher.serial_number <> rs.serial_number;

Upvotes: 1

Eric Petroelje
Eric Petroelje

Reputation: 60508

Did you already create the view? or do you already have a table named WritersCouples?

You could try this:

create or replace view WritersCouples as
select researcher.serial_number as S1, researcher.firstname as S2
from researcher, researcher as rs
where researcher.serial_number <> rs.serial_number;

Which would replace the view if it already exists.

Upvotes: 1

Related Questions