There is a user in my Oracle 12c database that has several views created from selecting columns from another user's tables. For example:
CREATE OR REPLACE FORCE EDITIONABLE VIEW "MYSER"."VIEW1" (column1, column2, column3)
AS SELECT (column1, column2, column3)
FROM OTHERSCHEMA.TABLENAME;
Now when running
select count(1) from MYSER.VIEW1
as sys user, I can see all the rows are there. However, as soon as I log into MYSER schema, and try to run the same select count statement, I either get a lower number or rows than the total, or no rows at all. (when doing this for several of the views done in the same fashion)
I have granted select on all of OTHERUSER's tables to MYUSER
This data was imported from another database. Not sure if that is what could be causing the issues.
EDIT: I have also tried granting
Grant execute on DBMS_RLS to MYUSER;
Thinking that it could be an issue with the partitions in the table. It could be something funky that the people that coded this application years ago enabled that I need to find out where they security levels or something in place.
Thanks!
A view is just a stored SQL statement.
When connected as myser
select * from view1;
should return exactly the same as
select column1, column2, column3 FROM OTHERSCHEMA.TABLENAME;
Related
I know this is DBA 101, but the question was asked and I have no answer ... well I guess what the answer is but need to confirm. I have a view (View1) that is a simple select of one table: Select col1, col2 .... from table1 where col2=0.
Table1 is indexed of course. When I run the Executation plan .. same results when selecting from the table or the view. So, would an index change anything on the view since it has no joins? Using SQL Server 2016.
Can someone explain the difference in semantics between the following:
select count(*) from dbo.SomeTable;
select count(*) from SomeTable;
select count(*) from ..SomeTable;
select count(*) from somedb..SomeTable;
select count(*) from somedb.dbo.SomeTable;
They all seem to yield the same results in my system.
More specifically I have this theory that somedb..SomeTable actually means:
the object SomeTable owned by the user I am currently connected as
in the database somedb.
Is this correct?
If so, given then that usernames appear to serve to partition table names into different namespaces, can't it be said that Sybase conflates the concept of a user to that of a schema? (since schemas are what other RDBMSs use to namespace tables?)
I need to create SSRS report where user need to look at the data many different ways(grouping, comparing etc). Using Visual Studio 2010. SQL server 2012.
I am using one stored procedure for that, dumping data into cte and from there doing all grouping.
My question is:
Is any way I can dump data from one stored procedure into #TempTable, then from that #TempTable into multiple views (grouping the way I need), and then in SSRS query that data from different views (use datasets as view).
Something like that:
CREATE PROCEDURE ProcName
(
#DateFrom datetime,
#DateTo datetime
)
AS
BEGIN
CREATE #TempTable
INSERT INTO #TempTable
SELECT Col1,
Col2,
Col3,
col4...
FROM Table1 INNER JOIN Table2
CREATE VIEW MyView1
AS
SELECT Col1,
Col2
GROUP BY Col1
FROM #TempTable
CREATE VIEW MyView2
AS
SELECT Col3,
Col4
GROUP BY Col3
FROM #TempTable
CREATE VIEW MyView3
AS
SELECT Col1,
Col4
GROUP BY Col2
FROM #TempTable
END -- End of SP
GO
And what would be the BEST way in terms of performance to create reports where user need to bread down the data all possible ways?
Right now I am trying to do every calculation in SSMS, then bring this data in SSRS. Performance is good, but sometimes I have up to 100 columns. It gets messy.
First of all, SSRS is not a very dynamic environment. It's difficult to predict every way a used will want to breakout the data. So my suggestion would be to offer a PowerPivot of the data in Excel as an alternative. That way, they can easily add and remove row/column groupings and see the subtotals. The slicers are also very handy.
More specifically to your question, I think in general the best practice would be to let the stored procedure just return all the raw data. SSRS is very good at grouping and sorting the data. That will put less strain on the server and require slightly more processing time. Of course, if you reach a point where there's just too much to process at run-time, you'll have to re-balance that workload or get more resources allocated.
Sometimes you have to get creative. For example, I have a report with almost 300 columns and over 100K rows. Normally it would take over 10 minutes to run or to export. So I turned on caching and scheduled a subscription to export it as a .csv each day. That way the data is available to open in Excel and the report is quick to re-run throughout the day.
I am creating a security layer on few databases. As part of that I have to create a view in Original_Database that joins two tables (union) from different databases, Chained_Database1 and Chained_Database2.
USE Original_Database;
GO
CREATE VIEW QueryATable
AS
SELECT * FROM Chained_Database1.dbo.ATable
UNION
SELECT * FROM Chained_Database2.dbo.ATable;
GO
If user usergroupA (Usergroup) logs in and selects from the view QueryATable from Original_Database then he should be able to see only data from Chained_Database1.dbo.ATable.
Likewise if usergroupB logs in and selects from the view QueryATable, then he should be able to see only data from Chained_Database2.dbo.ATable.
I have tried giving different permissions to the users. It's either denying view access or giving result from two tables.
Your help is highly appreciated.
Thanks in advance!
Based on your requirements, the UNION is pointless and would only slow performance since you would select from both data sets... and then explicitly limit it to one. Theoretically you'd have a look up table for the user who ran the query, and you'd limit the results in the WHERE clause since you can't user parameters in a view. So, don't do the union. Instead create two separate views.
CREATE VIEW QueryATable
AS
SELECT * FROM Chained_Database1.dbo.ATable
GRANT SELECT ON QueryATable TO <who ever...>
GO
CREATE VIEW QueryBTable
AS
SELECT * FROM Chained_Database2.dbo.ATable
GRANT SELECT ON QueryBTable TO <who ever...>
GO
If you don't want to create separate views then you could handle this in a STORED PROCEDURE or some other way perhaps...
CREATE PROCEDURE yourProcedure(#userID)
AS
IF 1 = (SELECT COUNT(*) FROM LookUpTableA WHERE userID = #userID)
SELECT * FROM Chained_Database1.dbo.ATable
IF 1 = (SELECT COUNT(*) FROM LookUpTableB WHERE userID = #userID)
SELECT * FROM Chained_Database2.dbo.ATable
ELSE
SELECT 'User Not Valid'
GO
Note that this assumes the user would only be in one of the look up tables. If they were in both you'd need to handle it differently.
i am creating a table in sqlserver database using query like "SELECT Table1.* INTO Table2 FROM Table1"
here Table2 created successfully but it is not showing my database
when i again fire this query than it gives error that Table2 is already created but i can't see this in my database
i am refreshing my database also
so please help me if anyone has solution..
#Ramesh has the right idea. In some situations (I think if your user is in the db_owner role?), SELECT INTO tables are created in the schema (the SQL 2005+ terminology) associated with your login. This may be something like YOURDOMAIN\username.Table2. If you go to select again from the same login, it will work fine, but chances are that other users will not be searching in your schema.
When in doubt, explicitly create the table in the dbo schema:
SELECT Table1.*
INTO dbo.Table2
FROM Table1
have you tried with the username.Table1, like
dbo.table
Its very important to append the username for any db object, it enforces the user to select the objects which he got permission to view