Presto SQL Server catalog not showing user defined tables - sql-server

I have two SQL Server catalogs. One of the SQL Server catalogs is showing tables only from master on execution of following commands whereas the other SQL Server catalog displays all the user defined tables.
Why the two catalog is behaving differently?
select * from ib.sys.tables;
show tables from ib.dbo;

There is difference in configuration (user + default instance) of presto sql server connector.
user used to create catalog have different set of permission /default schema and default data base .

Related

SqlServer Oracle linked server cannot see tables in the default schema

In Sql Management Studio (2012) I have set up a linked Oracle server which works fine. However, I cannot see or access any tables that are in the default schema (i.e., which do not have a schema name).
In other words I can do this:
SELECT * FROM (LinkName)..(SchemaName).(TableName)
but I can't do this:
SELECT * FROM (LinkName)...(TableName)
These tables also do not show up under the Linked Server tables folder, and doing a select returns the error "The table either does not exist or the current user does not have permissions on that table."
I know the tables are there and I have the appropriate rights because I can see and access these tables when working with SSIS on the same machine, and with the same credentials.
Any ideas?

Create a MS SQL View linking to a table in different host database

I have two databases. lets name them A and B. The database B is in different IP with different username and password. But I want to create a view in Database A linking to a table in Database B. How can I achieve this because of database B authentication.
You should create a linked Server in your Server in which DatabaseA exists.
You can google how to create Linked Server in SQL Server
EXEC sp_addlinkedserver
#server='ServerNameOfDatabaseB',
#srvproduct='',
#provider='SQLNCLI',
#datasrc='NCSUSPRODSQL02'
Once you create linked server then your view code would be something like the below.
CREATE VIEW Viewname
AS
SELECT *
FROM LinkedServerName.DatabaseB.SchemaName.TableName

Default schema for DROP and SELECT INTO in stored procedures

I am a bit confused as to how the default database schema is determined in MS SQL server.
I have the following stored procedure as a minimal working example:
CREATE PROCEDURE [dbo].[SampleSP]
AS
SELECT 'HI' as [SampleColumn]
INTO [SampleTable]
DROP TABLE [SampleTable]
All tests are executed using a user User on MS SQL server using Windows Auth with a default database schema of the same name.
When I execute this SP on MS SQL Server 2005 installation (running in compatibility mode 80, i.e. Server 2000) the table is created as [User].[SampleTable] and DROP TABLE fails with Invalid object name 'SampleTable' (I assume because it looks for [dbo].[SampleTable])
When I DROP TABLE [SampleTable] in a separate query it does work
When I execute the SP on MS SQL Server 2008 R2 (also running in compat. 80) the table is created as [dbo].[SampleTable] and dropped without error
I have found this answer describing the lookup in stored procedures, but it doesn't mention the user default in that context, even though it is used on 2005. Maybe someone knows how this changed and whether new versions can be configured to behave the same way.
It sounds like you just need to set the default schema for the user to dbo:
ALTER USER YourUser WITH DEFAULT_SCHEMA = dbo;
That way it's set at the user level and you won't need to alter any code.

How do I log what user deleted a record in MS Access?

It's a MS Access app with linked tables to SQL Server. I need to log this on the SQL Server as I cannot modify the MS Access app.
The app connects to the SQL Server through a default SQL username.
You will need a trigger for this, and a table to store the results. Very quick prototype:
CREATE TRIGGER dbo.trigger_name
ON dbo.table_name
FOR DELETE
AS
INSERT INTO dbo.LogTable(RowID, UserName)
SELECT PK_Column, SUSER_SNAME()
FROM deleted;
GO
Note that unless each Access user authenticates to SQL Server as themselves, you may need to use host name or some other property to identify them (if they all connect as the same SQL user, there is little SQL Server can do to determine who they really are).

Default role mapping when creating a MSSQL Server database

Is it possible to set up a default set of role mappings for Microsoft SQL Server (2008 R2 for instance) that apply to subsequent databases?
Example: Whenever I create a new database on the server, I want it to map db_owner to a login group called Group_A and db_datareader to a group called Group_B.
The databases are created by a 3rd party application, so doing it in the CREATE statement is not enough. What I hope for is to set a default behaviour for the server itself.
Every new database is created as a copy of the model database on the SQL server. So when you do the mapping the the MODEL db every new DB should replicate that. I haven't tried that with roles and groups but you can try it and let me know whether it works...

Resources