I have got a rather basic question but I could not find a confirmation about it online. When you create a view like the one below
create view report AS
select employee_id
from employees
It will store the data in a virtual table. That's ok. But when you add additional employee ids AFTER you have created the view will they be displayed when you run the view again? Cuz what I need is basically some view that will display the latest records I have added in the tables. Is that possible?
Short answer is Yes, it will update....
Ok, so Views don't quite "store" data, they just present data in a different format or select certain columns from a table to create your own "view" of the data.
If you are just looking to find the most recent employee ids through a view, I would recommend adding a column with a created or modified date field defaulting to the date entered. Then have your table do an Order By the datefield descending and select only top few rows so you only get recent records. The way to do this is slightly different depending on if you are using SQL, Oracle, or MySQL.
Related
I have a table person with columns of interest
id, ab_num, is_valid_act
The is_valid_act data is being modified by users many times.
We have been asked to build a service for a team that will only give them the changes that are happening on a is_valid_act column from person table and they can call X times a day.
The initial thought was to create a new table with the id, person_id, ab_num, is_valid_act. Then have a trigger for any time the person.is_valid_act column is modified.
Then the service can get the records where id > then the last id the other team is passing out. And we would manually seed their database.
But we worry about table becoming so big that they will lose performance.
Also, we could use the date based but we feel it like that could be error prone.
Another idea is to create a materialized view which only will get the newest records with Materialized View Log.
Any thought/ideas which way is better to go with?
Thank you
Would it be possible to create a view from a table showing all its fields in the original order but one without specifically naming all of them? Also, would it be possible to do the same but moving that field to the last column of the view?
I'm working on some current, and archived SQLite databases.
In current versions, a column is named message, but in the archived versions it's named message_id.
The query I'm running is pretty lengthy/complex, and it's just this one column that's changed. Is there any way I can do some kind of CASE EXISTS style query to do this, or am I just going to have to write a separate query?
I would suggest writing a view to access the historical data:
create view v_message_history
select message as message_id, . . .
from message_archive;
Then you can use the view and the two columns have the same name.
You could also use alter table to rename the column in either the history or current table. I am guessing, though, that you don't want to do that because it might break existing code.
Can anyone please share the steps to hide the particular column from the table in SQL Server 2012 as I don't want to delete that column
By hide I mean that whenever I use the select query against that particular table it should never show me that column.
Is it possible?
I need to make the column as hidden irrespective of any user login and whatever query i use
3rd party edit
Based on the comment But the problem is whenever i open the table in sql i dont want to see that particular column i assume that the question is:
How can i configure ssms so that opening a table definition inside sql management studio to only show the columns the connected user has select right to?
The screenshot below shows all columns of the table Employee despite the fact that the login StackoverIntern has no select rights to the columns SSN, Salary
Late post but I think its worth to share
Earlier to SQLSERVER-2016 there was no any option to hide few columns from table when selecting *, however SQLSERVER-2016 come up with HIDDEN keyword by which you can now set columns hidden from Select * which you don't want to show and want only for some background process of your business logic.
The HIDDEN property is optional and will hide these columns
from a standard SELECT statement for backward compatibility with our
application and queries. You cannot apply the HIDDEN property to an existing column
.
you can alter existing table as well lets take an example of existing table
ALTER TABLE [dbo].[Account] ALTER COLUMN [StartDate] ADD HIDDEN;
ALTER TABLE [dbo].[Account] ALTER COLUMN [EndDate] ADD HIDDEN;
You can check this concept used more often in Temporal table
you can find more on this in below Temporal Table
You can use column level permissions so that targeted users cannot select on that column. However, this will not "hide" the column in the case of doing a SELECT * or SELECT SpecialColumn. Instead, it will fail the query, resulting in an error.
An alternative to allow easier queries, you can make a View that does not include this column:
create view MyTableEx As
SELECT Every, Other, Column
FROM MyTable
Then only grant SELECT permissions to the View, rather than the table, for certain users. However, this is still problematic for an application, which now has to know whether it should select from the Table or the View.
When it comes down to it, column level permissions are kind of an unnatural thing to do in a database.
If you do not want the column to show, then you should not include it in you select statement. It is also more efficient to not use an asterisk (*) in your select statement.
See this post for more info in the performance issue:
Performance issue in using SELECT *?
Does anyone have a knowledge of a tool that allows to navigate over reliationships between entities in sql server database?
I want to be able to list all rows in a table and then (for selected row) jump to all rows that match (in a context of relation between tables).
The same thing can be done in LINQ to SQL by querying navigation properties but it's not convinient to do this in code all the time.
I tried to use LINQPad but query results are not interactive in this way - again it can be done in code.
Thanks for answers in advance:)
Try PL/SQL Developer, It should be working as you expect.
For eg: If we view a table, the 1st few rows of the table will be shown.
Then when you want to go to a child table or parent table from that. You had 2 types of hierarchy button for each.
The button circled in image was one of them. And this one particularly was for finding child references from this table.
On clicking it you will be show you the table references from this table using the foreign key relation ship. And on selecting one of them it will change the sql query to filter out with the table and column you selected.
The application was a bit different from other tools out in market, but once you got to know how to use it.
I think this is their home page