I am not able to drop a table from my Database.
For the query select owner from ALL_TABLES where TABLE_NAME ='db_schema_version'; I see the result as OWNER_FC
For the query show user; I see the result USER is "OWNER_FC"
But when I try to drop the table using the query drop table db_schema_version cascade constraints; then I get the below error:
drop table db_schema_version cascade constraints
Error report -
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Since I am the owner I dont understand why I am not able to drop the table?
I think this table is created by Flyway but I am not sure if that is relevant information here
For the query
select owner from ALL_TABLES where TABLE_NAME ='db_schema_version';
I see the result as OWNER_FC
The table name is in lower-case in the data dictionary. This means you need to provide the table name in lower-case in your query, for which you need to surround it in double-quotes, and you may need to specify the schema:
DROP TABLE "db_schema_version" CASCADE CONSTRAINTS;
or
DROP TABLE OWNER_FC."db_schema_version" CASCADE CONSTRAINTS;
Related
I'm using SQLite, which doesn't support adding a constraint to an existing table.
So I can't do something like this (just as an example):
ALTER TABLE [Customer]
ADD CONSTRAINT specify_either_phone_or_email
CHECK (([Phone] IS NOT NULL) OR ([Email] IS NOT NULL));
Are there any workarounds for this scenario?
I know:
I can add a constraint for a new table, but it isn't new (and it's generated by my ORM, EF Core)
I can do a "table rebuild" (rename table, create new one, copy old data, drop temp table) but that seems really complex
Ideas
Can I somehow make a copy of the table into a new table, with some schema changes?
Or "get" the schema somehow, and edit it in a SQL script, then add a table with that schema?
To make a copy of a table with some schema changes, you have to do the creation and the copying manually:
BEGIN;
CREATE TABLE Customer_new (
[...],
CHECK ([...])
);
INSERT INTO Customer_new SELECT * FROM Customer;
DROP TABLE Customer;
ALTER TABLE Customer_new RENAME TO Customer;
COMMIT;
To read the schema, execute .schema Customer in the sqlite3 command-line shell.
This gives you the CREATE TABLE statement, which you can edit and execute.
To change the table in place, you can use a backdoor.
First, read the actual table definition (this is the same as what you would get from .schema):
SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'Customer';
Add your CHECK constraint to that string, then enable write access to sqlite_master with PRAGMA writable_schema=1; and write your new table definition into it:
UPDATE sqlite_master SET sql='...' WHERE type='table' AND name='Customer';
Then reopen the database.
WARNING: This works only for changes that do not change the on-disk format of the table. If you do make any change that changes the record format (such as adding/removing fields, or modifying the rowid, or adding a constraint that needs an internal index), your database will blow up horribly.
I have a sqlite3 database. A single table inside this DB can't be dropped, the error message says unknown tokenizer: mm.
I tried it directly with the command DROP TABLE tablename; inside the newest SQLiteSpy v1.9.11 and also within .NET code and the official sqlite NuGet package v 1.0.103.
How can I drop a table where the tokenizer is unknown?
The documentation says:
For each FTS virtual table in a database, three to five real (non-virtual) tables are created to store the underlying data. These real tables are called "shadow tables". The real tables are named "%_content", "%_segdir", "%_segments", "%_stat", and "%_docsize", where "%" is replaced by the name of the FTS virtual table.
So to get rid of that table, drop the shadow tables:
DROP TABLE tablename_content;
DROP TABLE tablename_segdir;
DROP TABLE tablename_segments;
DROP TABLE tablename_stat;
DROP TABLE tablename_docsize;
And then use the (very dangerous) PRAGMA writable_schema to remove the remaining information about this table from the system table:
PRAGMA writable_schema = ON;
DELETE FROM sqlite_master WHERE type = 'table' AND name = 'tablename';
SQLite caches schema information, so then you need to close and re-open the database.
Sorry im new to Oracle store procedure, I have a cursor declared to query table from another schema as following:
CURSOR A IS select * from <schema>.Employee where conditions
My schema's name is actually being kept in a table, say, Table A, so I need to query from Table A and pass it in the cursor as variable.
Does anyone know how I could do that?
I have suddenly got the following error:
FK_dbo.TimeHoursWorked_dbo.Employee_EmployeeId' is not a constraint.
Could not drop constraint. See previous errors
I dont get it as there are no tables called dbo.TimeHoursWorked or dbo.Employee (I do have tables TimeHoursWorked and Employee.
You do actually have tables called
dbo.TimeHoursWorked and dbo.Employee..
dbo stands for Database Owner, and each table that does not have an owner specified, gets assigned to dbo.
A fully qualified SQL table is
<databaseName>.<owner>.<tableName>
You can use SELECT * FROM Employee which assumes the current database or you can use SELECT * FROM Payroll.dbo.Employee which looks in the Payroll database for a table called Employee owned by the database owner
I want create table from another table with constraint?
I used this query "create table destination as select * from source;" fro table creation.
But its copy only the column name in table without column constraint.
There is a special table named sqlite_master, holding the full CREATE TABLE statement for each table (it's modified as appropriate during ALTER TABLE).
I would make my application retrieve that CREATE TABLE statement:
SELECT sql FROM sqlite_master WHERE type='table' AND name='source';
Then I would replace the table name right after CREATE TABLE tokens, and execute the result as a new sqlite query.
I don't think that it's possible to do in sqlite's pure SQL without extensions.