How to drop "GRAPH" on AgensGraph? - agens-graph

I tried to drop graph. An error occurred when dropping graph.
# drop graph graph;
ERROR: cannot drop graph graph because other objects depend on it
DETAIL: sequence graph.ag_label_seq depends on schema graph
label ag_vertex depends on schema graph
label ag_edge depends on schema graph
HINT: Use DROP ... CASCADE to drop the dependent objects too.
How to drop "GRAPH"?

When dropping graph, all data & schema must be drop before.
For convenience, optional "CASCADE" clause is usable.
# drop graph graph cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to sequence graph.ag_label_seq
drop cascades to label ag_vertex
drop cascades to label ag_edge
DROP GRAPH

Related

How to cascade the data type of a column of a table in postgres

I have a PostgreSQL database and I need to change the data type of a column. There is a view that uses that table. Is there any way to change the data type of the column without deleting the view using ALTER TABLE table_name ALTER COLUMN column_name TYPE new_type.
No, you will have to drop and re-create the view.
The pg_get_viewdef function that calculates the definition of a view will be helpful.
You can do the whole operation in a transaction if you don't want to expose the "view-less" state to concurrent transactions.

How to drop all graphs on AgensGraph?

I want to drop all graphs on agensgraph with drop database.
Is there query finding all graphs?
agens=# SELECT GRAPHNAME FROM ?????;
graphname
-----------
graph1
graph2
Use AG_GRAPH table for finding all graphs.
And drop graph one by one.
agens=# SELECT GRAPHNAME FROM AG_GRAPH;
graphname
-----------
graph1
graph2
graph
(3 rows)
agens=# DROP GRAPH GRAPH CASCADE;
NOTICE: drop cascades to 4 other objects
DETAIL: drop cascades to sequence graph.ag_label_seq
drop cascades to vlabel ag_vertex
drop cascades to elabel ag_edge
drop cascades to vlabel v
DROP GRAPH
agens=# DROP GRAPH GRAPH1 CASCADE;
NOTICE: drop cascades to 5 other objects
DETAIL: drop cascades to sequence graph1.ag_label_seq
drop cascades to vlabel ag_vertex
drop cascades to elabel ag_edge
drop cascades to vlabel v
drop cascades to elabel e
DROP GRAPH
agens=# DROP GRAPH GRAPH2 CASCADE;
NOTICE: drop cascades to 5 other objects
DETAIL: drop cascades to sequence graph2.ag_label_seq
drop cascades to vlabel ag_vertex
drop cascades to elabel ag_edge
drop cascades to vlabel v
drop cascades to elabel e
DROP GRAPH

Turn off system versioning of temporal table that is used in indexed views

I have a table that is used by a number of indexed views that I want to convert to a temporal table. All the commands to add the necessary columns and to set SYSTEM_VERSIONING=ON with a history table all succeeded. But now I can not disable system versioning with this command
ALTER TABLE [dbo].[MyTable] SET(SYSTEM_VERSIONING = OFF);
I get the error
Cannot ALTER 'MyTable' because it is being referenced by object 'MyIndexedViewThatReferencesMyTable'.
It seems impractical to delete all views, alter MyTable, then recreate all views in order to accomplish this. Is there another way to get this table back to non-temporal?

Remove record from sys.objects?

I ran a ALTER SCHEMA ... on a table (SQL Server 2012 SP1) but the sys.objects record is still there. When I run the ETL I get an error that the table doesn't exist anymore because it's trying to remove all constraints. This one is of type PK Primary Key Constraint. How can I safely remove the record from the sys.objects table?
I managed to fix this issue by scripting the database to a new one, ALTER SCHEMA ... again on that table to bring it back to dbo., then DROP and recreate the table in the different table schema.

What is the difference between drop table and delete table in SQL Server?

In SQL Server, what is the difference between the following two-
Right click on a database object (table/view) and opt for Drop table (i.e. Script table as -> DROP To -> New Query Editor Window)
Right click on a database object (table/view) and opt for Delete.
I tried them both and both perform the same action. Any reason for having two options for the same thing? Is the Delete option just a crude way of dropping the DB object?
Just for the record - I'm using SS2008.
DROP will delete all data and the table structure as well.
DELETE will delete the data but the table structure will remain the same and we can still rollback the data. Also with DELETE you can use the where condition i.e. to delete only certain records.
it is drop table and delete object, at least in SQL Server 2005. Both perform the same action.
Delete table and Drop table are not the same though. The former will delete all data from the table whilst the latter will remove the table from the database.
Delete v/s Drop.
Delete statement performs conditional based deletion, whereas Drop command deletes entire records in the table.
Delete statement removes only the rows in the table and it preserves the table structure as same, and Drop command removes all the data in the table and the table structure.
Delete operation can be rolled back and it is not auto committed, while Drop operation cannot be rolled back in any way as it is an auto committed statement.
One of these performs a delete, the other provides you with the TSQL script to do a delete so you can modify or use it elsewhere.
Those two are the same operations. DROP TABLE is SQL statement for this, Delete is standard, user-friendly, menu-driven command name. That's all.
In the delete object GUI, on top there is a 'script' option which gives the t-sql statement which is plain drop table statement. Where as when you go for the drop table option, the t-sql generated would perform drop only if the table exists in the sys.objects table.
Drop table..it will delete complete table from the Database.it can not retrieved bak
Delete is used to deleting data from the table.. data can be retrieved using ROLL BACK.
Another major difference is that in DELETE it will traverse/scan to all(conditional based on predicate) the records and does delete. But in drop it will traverse records instead it will remove the actual table entry from database. If we look at execution plan for Delete:
In case of Drop as it is DDL command it will not even traverse records and will not create any execution plan.
If you choose Delete, then choose to script it, you will see that it gives you a drop table statement as well.
Using Delete command rows can be deleted from table conditionally, but changes can be done/undone by using COMMIT and ROLLBACK. Table structure is never lost. Truncate is an alternative of Delete in the sense that it allows Deletion of rows without losing the table structure but UNLIKE Delete, operation can't be undone. Drop statement however, removes the table completely along with its structure from the database and this operation can't be undone. So, Delete is a DML statement and Turncate and Drop are DDL statements.
Drop table will delete the content of the table and the table self.
Delete table will just drop the content.
Truncate will just 'reset' the content to zero
We can delete the particular record from a table with using delete command . but using drop we can drop the tables. if you use Drop the structure will also go, but if you use delete command the structure won't go.

Resources