Create a view that exists even if session ends in Redshift? - view

I am trying to create a view in Redshift.But when I close the session and again reopen it then given view is not present.How can I create a view that exists even if my session expires?

Views are not session dependent. They'll exist in storage like any other table.
Are you prefixing your create view [] statement with a schema name i.e. create view schemaname.viewname? If not, the view will either get created in your public schema or the default schema search path.
A way to troubleshoot is to go through the different schema listed and then find out where your view has been created.
If you find your view in public schema, you'll get to know that if no default search path is set and schemaname is not mentioned while creating tables/views, it gets created in the public schema by default.
If you find your view in any other schema, you'll get to know what your search path is.

Views are persistent.
Some possible reasons why you can't see the view:
You are connecting as a different user who has a different Schema search path
You are connecting to a different database
You created the view in a different schema and when you reconnected you went to a default schema

Adding to previous answers, the view dependencies (tables that are used in the view definition) might be dropped and view is dropped consequently.

Related

Update view schema

Hi I would like to be able to update a view to point to a table in a different schema as in example below, change SCHEMA1 to SCHEMA2. No other change to the SQL.
Can anyone suggest an efficient way to achieve this, ideally a string replacement.
I can do CREATE OR REPLACE FORCE VIEW and provide the list of fields. This doesn't seem a good option as I have about 40 views re repoint.
CREATE OR REPLACE FORCE VIEW CUST.CustOrdersView as
SELECT field1, field2 etc.. from
SCHEMA1.CUSTOMER ;
Your problem is simply that you have hardcoded the schema name in the views' queries. Instead of that you could have created a synonym:
create synonym CUSTOMER for SCHEMA1.CUSTOMER;
Then in your view you would have simply referenced CUSTOMER.
To repoint the view to another schema you would have to change the synonyms:
create or replace synonym CUSTOMER for SCHEMA2.CUSTOMER;
That's still work but it's much easier to generate those statements from the data dictionary views than it is to change all the view queries.
(If there is a namespace clash - that is, if schema which owns the views already has an object called CUSTOMER - you would need to use a different name for the schema.)
You may not regard this as a helpful answer, because it doesn't really solve your current problem, but it may help you avoid a similar situation in the future.

Maximo: How to enable search in list tab in application where main object is view

Suggestions are appreciated.
I created DB view ABC_VW in maximo database.
Created object with name ABC_VW in maximo.
Created power application with name ABC with main object ABC_VW in maximo.
On list tab the search is disabled.
How can I enable the search?
Note: I tried updating search type to WILDCARD from backend in both tables MAXATTRIBUTE and MAXATTRIBUTECFG but no luck.
Please suggest.
Whenever a view is created in DB and object is created on the view, a primary column has to be updated in MAXATTRIBUTECFG table as
update maxattributecfg set changed='Y', searchtype='WILDCARD', primarykeycolseq='1', defaultvalue=null, maxtype='ALN', length=22 where objectname='ABC_VW' and attributename='XXXXXX';
update maxobjectcfg set CHANGED='A' where objectname in ('ABC_VW');
Then apply configuration changes from the Database Configuration.
This is how the field from view can made searchable.

How to create read only tables in MS Access 2013?

I would like to create a forms in my Access database which will save data to existing tables. This data entry form will save all valid data to the specified tables.
Now I would like to restrict the table from direct entry, i.e. no one can edit/update data directly in tables.
So please suggest me know can I do this.
You can not make something readonly AND not readonly. The forms need the tables to be writable.
What you can do is hide the tables, see: http://office.microsoft.com/en-gb/access-help/show-or-hide-database-objects-HP005188361.aspx.
If you need the tables for lookups you can make a readonly query based on the table. You have to change the query type to snapshot.

Changed existing entity model and manually updated SQL Server database but still get context changed error

I have an existing MVC3 application and database that is on a SQL Server 2008 R2 and I had to add a bool item to an existing model.
After I added it to the model, I rebuilt and published the project. Then I opened up SQL Server Management Studio and went to the table and added the entry to the column as a bit, I had to make it nullable since the table already contains data.
I thought this would be all that I would need to do to get everything working. However I got this error:
The model backing the 'psllc_DB' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
I'm not sure what else to do, I went back to the code and changed the bool to bool? so it will be nullable but this didn't help either. I can't drop the entire database since it's full of data, however as a last ditch possibility I could drop this table and re-create it cause it only has a few entries, but I don't know if that will work. I'm not sure what else to do so any advice would be very appreciated.
Update
Since I'm not getting any responses, let me rephrase my question.
How should I update my database (a SQL Express mdf file) to add a bool Column to a Table that has data already? I need the database to match my updated MVC 3 Entity Code First model otherwise I get the above error.
Thanks
Since this is code-first, you should do this code-first: change the class and use EF-migrations to change the database. The way you do it, the model and the database may match, but the meta information in the database is not updated.
By the way, if you supply a default value, you can add a non-nullable column.

Linq-to-SQL How to prevent the use of Delete methods?

By convention our DB only alows the use of stored procedures for INSERT, UPDATE and DELETE. For some tables / types there is no DELETE stored procedure, because it is not allowed to delete rows. (You can only update the status of such a type to "deleted"). e.g. a customer may be marked as deleted but is never really removed from the DB.
How do I prevent the use of Delete() for certain types in the Data Access Layer = in the DMBL?
The "Default Methods" for Insert and Update are mapped to the corresponding stored procedure. But for Delete it says "use runtime". I would like to set it to "not allowed".
Is there a way to achieve this on the DB model layer?
Many thanks
Implement a partial class for each such entity and implement the OnValidate partial method. It takes a ChangeAction as a parameter. When the ChangeAction is ChangeAction.Delete, throw an exception that indicates that the operation is disallowed (IllegalOperationException, maybe).
I had the same constraint while developing one of my application. You can always condifure the delete action to use a certain stored procedure instead of the framework generating a sql command for the same. In my case when I say delete we just wanted to mark a particular row as deleted but not physically deleting it. So our update stored procedure was reused in the delete command to simply mark the isDeleted col value as true. Besides that you may want to build some kind of wrapper around the classes built by DBML and suppress the delete methods. Right now I do not see any speciall setting to have the framework only generate create and update methods. Partial classes may be one more alternative.
How about to configure rights for the user you're using to connect to DB? You can set Deny for Delete operation for this particular user, so it wouldn't be possible to use DELETE statement on DB level.
The deletion API is not generated, by which I mean an option on a generated table cannot remove the ability to mark an item as deleted. DeleteOnSubmit is part of the Table<TEntity> class.
If it is always an error to delete an entity, OnValidate should throw an InvalidOperationException as tvanfosson suggests.
I tried mapping Linq to Sql deletes to stored procedures which simply set the field to true. It gets weird because the DataContext removes instances after "deleting", but they are legal domain entities and should still be in the DataContext after submitting.

Resources