There is already an object named "Test" in the database while adding a role using SP_AddRole in SQL Server 2012 - sql

I am trying to add a role in my master database in SQL Server 2016 using below command:
SP_AddRole 'test'
I am getting this error:
There is already an object named "test" in the database.
I have checked expanding Roles in my master database, and I found that there is no Role with name "test" in my master database.
Still I have tried to Drop that Role using below query:
Drop Role 'Test'
I get this error:
Cannot drop the role because it does not exist or you do not have permissions
When I try to alter Role using below query:
Alter Role Add Member "Domain\userName"
I was getting same error as below:
Cannot alter the role because it does not exist or you do not have permissions.
Note: I have all permissions and privileges to SQL Server and master database.
Can someone please suggest what can be done in order to resolve this?
I can't change the name of the role as it is very important for my applications to create a role with this name.

There was an already created SCHEMA in that SQL Server database.
I have deleted that schema
DROP SCHEMA Test
And then below SQL query worked.
SP_AddRole 'Test'
When I create Role, a default schema with same name gets created which was visible when I expand Schemas.
When I try to Drop the Role, I will need to first Drop the schema and then the Role.
Even if the schema with same name(But Role does not) present, SQL Server does not allow me to create new Role with same name.
Reference here

Related

How to elevate Permissions in Azure Synapse SQL Server

When I attempt to drop an external table in Azure Synapse SQL Pool I get the folloiwng error:
Cannot drop the EXTERNAL TABLE 'TableName', because it does not exist or you do not have permission.
I am accessing Synapse SQL Server via SSMS.
Can someone let me know how elevate my permissions to drop an external table please.
Theis error generally cause two reasons one is you are table might not present in that particular data baser or the user with which you are querying that table has not have proper privileges.
To Drop Any external table, you need below three major permissions like Alter any schema, alter any external data source and alter any external file format as #Jon suggested.
GRANT ALTER ANY SCHEMA to {user};
GRANT ALTER ANY EXTERNAL DATA SOURCE to {user};
GRANT ALTER ANY EXTERNAL FILE FORMAT to {user};
And also db_exporter server role is there which grant all this permission to you user.
ALTER SERVER ROLE db_exporter ADD MEMBER {user} ;
Also make sure you are using appropriate database to be querying your table where it is present.
And also make sure there is no DENY permission on your user

can't read data from a few specific tables with db_datareader role

I do have admin permission for a certain Azure SQL Server. So using my admin login I created a database user against a specific Azure SQL database in the following manner:-
CREATE USER myuser WITH PASSWORD = '<pwd>'
ALTER ROLE [db_datareader] ADD MEMBER [myuser]
After this I successfully logged into the database using this new credential for myuser. I discovered that while I can query data from most of the tables , there are certain tables for which I can't select any data. I can see the table name in SSMS , also no error for SELECT queries against those tables I receive , the only issue is that SELECT doesn't return any data ( 0 rows ) for those tables. If I fire SELECT using my admin credentials , I can very much see the result.
I tried to reproduce the same issue using the same commands which you have shared.
FYI, as a part of repro, I created an Azure SQL Server and then SQL database in the same server. I added three sample tables to match the scenario as you mentioned. Then I created user and grant db_datareader role with the same commands as you mentioned. It worked fine for me. I’m able to read the data of all the table in that specific database.
I suggest you consider How to Create Login, User & Assign Permissions in SQL Server and Overview of db_datareader role.
Alternatively, you can grant select permission to those tables which you are unable to read using below command:
GRANT SELECT ON <tablename> TO <user>;

how to create a user in oracle 12c

i want to create a user in oracle 12c but i have a problem.after i enter my user name and psw, this warning displatyed: ORA-65096: invalid common user or role name
If you see this error then first you need to alter the session for oracle 12c:
alter session set "_ORACLE_SCRIPT"=true;
after running above command you can create the user. it will work for sure.
CREATE USER your_username IDENTIFIED BY your_password;
Connect first to your pluggableDB
CONN system/systempassword#//localhost:1521/pluggabledatabase
Than you can create your user:
create user marcopolo identified by marco9274;
Note:
You must have created the database as a container database. While, you are trying to create user in the container, i.e. CDB$ROOT, however, you should create the user in the PLUGGABLE database.
You are not supposed to create objects in the container, the container holds the metadata for the pluggable databases. You should use the pluggable database for you general database operations. Else, do not create it as container, and not use multi-tenancy.
See (error: ORA-65096: invalid common user or role name in oracle)
connect system/manager as sysdba
alter session set "_ORACLE_SCRIPT"=true;
create user your_user_name identified by your_password;
grant dba to your_user_name;

SQL Server 2016 - Error 15150 trying change usermapping

I'm trying to add db_backupuperator to a UserMapping but I can't. It returns the Error 15150 and the message:
"Drop failed for User 'dbo' (Microsoft.SqlServer.Smo)
Additional information:
an exception occurred while executing a Transact-SQL statment or batch
(Microsoft.SqlServer.ConnectionInfo)"
I've already tried apply these sugested solutions:
https://blog.sqlauthority.com/2017/12/12/sql-server-fix-msg-15150-cannot-alter-user-dbo/
Use database_name
sp_changedbowner 'sa'
I've tried also delete the database and create a new one, but then I can't edit any option of User Mapping, can't even add db_datareader or db_datawriter
If the user is member of the dbo database role, you will first have to remove him from this role. If he is the database owner, you will first have to change the database owner to another user. Then afterwards you can grant thim indivually the permissions needed, or create a database role which includes the permissions and put him in that role. This will be much more easier, if you have additional users holding the same rights as the mentioned user.
Reference link from Here.

DBA readonly account

I had a schema in one oracle DB as ui_prod. I asked my DBA team guys to create exactly same schema like ui_prod but as read only and name it ui_prod_readonly. Usually I will use Oracle SQL developer to connect a DB and query directly with table name like below.
--Connect to ui_prod
select * from table
but why I requested to put owner name infront when query for readonly schema they created for me, as without putting it, I get error table not exist.
--Connect to ui_prod_readonly
select * from ui_prod.table
I have project files which hardcode the sql query with only table names and adding owner name in front will cause many changes and effort. Can anyone explain me on this? or provide me any document/link to read. Thanks
You should look into synonyms, apparently the user you are connecting to the database as is not the owner of the objects. So to view the object you have to prepend the names with the schema name (the owner of the object themselves).
http://www.techonthenet.com/oracle/synonyms.php
CREATE OR REPLACE SYNONYM ui_prod_readonly.synonym_name
FOR ui_prod.object_name
It seems to me that your dbas have not created another set of tables but just granted the existing tables to the user ui_prod_readonly.
When you log in to Oracle, the current schema is the name of the user you used to log in. So if you log in with ui_prod_readonly Oracle checks that schema for the table if you do not qualify it with the owner (=schema).
If you want to change the current schema so that you don't need to fully qualify the tables, you can do that with ALTER SESSION
alter session set current_schema = ui_prod;
Once you have done that, you don't need to fully qualify the table with the owner (=schema).
if you need a user to read the data only
its simple to create new user and grant it only select privilege
you can create user and grant select privilege using
CREATE USER [user] IDENTIFIED BY [your_password];
grant select on table to [user]