I created view with name 'ATM_BRANCH' but there was some error in sql statement so view did not created. But now after correcting error, I tried again but it gives me error 'There is already an object named 'ATM_BRANCH' in the database'. Then I see the views in Object explorer and there is no view with this name. I need to create the view with same name. What to do?
My guess is that the view is actually still there, in some form. First run this to confirm:
SELECT EXISTS(SELECT 1 FROM sys.views WHERE name = 'ATM_BRANCH' AND type = 'v');
If that returns true, then drop the view:
DROP VIEW ATM_BRANCH;
Based on your comment, and Gordon's correct guess, ATM_BRANCH is actually a table. So, if you want to name a view ATM_BRANCH, you'll have to drop the table first:
DROP TABLE ATM_BRANCH;
Related
Im getting an error at DROP TABLE but I cant figure out why. My table PLAYER_OBJECT is already coded and working but even if the table is created the error on drop table wont go away. What I my doing wrong.
DROP TABLE PLAYER_OBJECT
CREATE TABLE PLAYER_OBJECT()
You could simply put IF EXISTS between TABLE AND PLAYER_OBJECT, like this:
DROP TABLE IF EXITS PLAYER_OBJECT
You problably have an error in the creation of you table or you didnt launch your code.
I want to be able to make CTE to make the below SQL work, I am getting the error
ERROR: Cannot replace a normal view with a late binding view for the below SQL, any way I could change it up so that it doesnt bind with schema views?
CREATE OR REPLACE
VIEW "dev"."XXBRK_DAILY_FX_RATES" ("F_C", "CURRENCY", "C_D", "C_R") AS
SELECT DISTINCT GL.GL_R.F_C, GL.GL_R.CURRENCY,
GL.GL_R.DATE, GL.GL_R.C_R
FROM GL.GL_R
with no schema binding
WHERE GL.GL_R.C_T='Corporate'
UNION ALL
SELECT DISTINCT GL.GL_R.F_C, GL.GL_R.F_C CURRENCY, GL.GL_R.DATE, 1
FROM GL.GL_R;
So you seem to have a statement issue. The last 4 lines are after the ';' and not part of the statement being run. I'm guessing that these are extraneous and posted by mistake.
Views on Redshift come in several types - normal and late binding are 2. The view "dev"."XXBRK_DAILY_FX_RATES" seems to already exist in your cluster so your command is trying to replace it, not create it. The error message is correct, you cannot replace a view with a view of a different type. You need to drop the view, then recreate it as late binding.
Now be careful as other objects dependent on this view will be impacted when you drop it (especially if you CASCADE the drop). When you drop and recreate the view it is a new object in the database but replacing a view just make a new definition for the same object. Understand the impacts of drop to your database before you execute it.
CREATE VIEW CARAVAN AS
SELECT ANNUAL_RENT, BOOKING_FEE
FROM CARAVAN
WHERE ANNUAL_RENT < 3000
this is my failed sql. the error is
ORA-00928: missing SELECT keyword
Try running just the SELECT statement:
SELECT ANNUAL_RENT, BOOKING_FEE
FROM CARAVAN
WHERE ANNUAL_RENT < 3000
And see if that returns a result, or if it generates an error.
My suspicion is that CARAVAN is a view that is INVALID. You can check that with a query from a dictionary view, e.g.
SELECT *
FROM dba_objects
WHERE object_name = 'CARAVAN'
If you don't have privileges on dba_objects, then reference the all_objects instead.
The referenced CARAVAN object is either an object in your schema, a public synonym, or its an invalid reference.
As Alex Poole mentioned, it's possible to create a view that has invalid syntax, by using a CREATE FORCE VIEW statement. (I suspect that the referenced object CARAVAN is a view that contains invalid syntax.)
Identifiers in Oracle have to be unique within a schema. It's very strange that you would be creating a view named CARAVAN that references an object already named CARAVAN. It's not clear what problem you are trying to solve with this particular CREATE VIEW statement.
I am in a situation where I want to drop a view or table, but can only know at run-time which it is (same identifier though). This does not work:
DROP VIEW IF EXISTS my_table_or_view;
Because if my_table_or_view is a table, it will throw:
android.database.sqlite.SQLiteException: use DROP TABLE to delete table my_table_or_view
Likewise, I cannot use DROP TABLE, because it tells me to use DROP VIEW if i have a view at hand. I could catch the error, of course, but since this is part of a larger transaction, I would definitely prefer an answer that works using pure SQL (as understood by sqlite3). Any ideas?
You can get information about items in your sqlite database by SELECTing from a pseudo-table called sqlite_master.
In this case, you would do:
SELECT type FROM sqlite_master WHERE name = 'my_table_or_view'
and the resulting information will tell you whether you're dealing with a table or a view.
More info: http://www.sqlite.org/faq.html#q7
I am trying to insert data from one table to another with same structure,
select * into tbltable1 from tbltable1_Link
I am getting the following error message:
There is already an object named 'tbltable1' in the database.
The SELECT INTO statement creates a new table of the name you provide and populates it with the results of the SELECT statement.
I think you should be using INSERT INTO since the table already exists. If your purpose is in fact to populate a temporary table, then you should provide a table name that does not already exist in the database.
See MSDN for more information on this.
If you are confident that tbltable1 is not required, you can drop the table first.
You may also want to consider using temporary tables...
Select * into ##MyTemporaryTable FROM tblTable1_Link
You can then use the temporary table in this session. (Ending the session should drop the temporary table automatically, if I remember correctly. It's been a while since I've worked with SQL Server).