How to alter secondary database in high availability group? - sql-server

I want to run an alter database command (change the owner) but being part of the HA Group, the database is in read-only mode. I changed the primary so I am guessing I have to force a failover and then update it? Is there a simple way to unjoin or suspend (looks like suspend keeps the read only mode turned on), make the change, and then join it back?

The database owner detail is stored in the master.sys.sysdatabases table, and not on the user database. So when you run the statement on the primary database, it will not transfer to the secondary database.
Changing the database owner requires a read-write database.
try failing over to the secondary database and make it as new primary database, and then change the database owner of new secondary database. then switch back to primary
Reference: Perform a Planned Manual Failover of an Availability Group (SQL Server)
Regards,
Suing

Related

Azure SQL database upgrade

Im wondering something regarding this article:
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-manage-application-rolling-upgrade
We would like to perform a database upgrade involving ~3 million records in a table. The upgrade will add an extr column to the mentioned table, which can take up to 5 minutes to complete.
In short, Microsoft suggest creating a transactionally consistent database copy of the target database, perform the database upgrade/migration and switch users to that copy using a load balancer.
This seems all and well, but records created in the original database will not be present in the upgraded/migrated database copy.
Turn the primary database to read-write mode and run the upgrade script in the stage slot (5). - is what the article suggest.
If the primary database is read-write mode, won't i be missing data in the upgraded/migrated copy of the primary database once i point everyone to the new database?
For example: would it be possible to sync database records from the primary to the secondary once the secondary is upgraded and front-end users are pointed to the secondary database?

Database Difference on publisher and subscriber

I currently have SQL Server Transactional replication running. Server A (Publisher & Distributor) to Server B (Subscriber). Everything is working great. I just need to know whether i can add a table to the subscriber only in that database? will it affect my replication? must the databases be the exact same in terms of schema etc?
I need to add a table that's not part of the publishers published articles on Server B(Subscriber).
I just need to know whether i can add a table to the subscriber only
in that database?
Yes, you can. It won't affect to the replication, but, for example, if you create table dbo.A on subscriber database first and later you'll create table with the same name and schema on publisher database you can lost data in table dbo.A on subscriber because by default new articles on the subscriber will be drop if exists within initialize process.
You can change this behavior in publication properties.
must the databases be the exact same in terms of schema etc?
No, it must not. In transaction replication you can replicate either whole tables or some columns of those tables.

Is there a command to stop using a database in SQL Server?

I'm refering to when we say USE dbTest we start using that database and we can create tables and what not, and if we want to change databases we could just say USE dbNotatest and it would change the database we're using.
But is there a way to stop using the database we selected in the first place, without starting to use another one?
To stop using a database, you will need to change your database context. For example, if you are trying to drop your database and you are in the context of that database, simply switch to another database (commonly master or tempdb).
If other connections are open to the database and preventing you from dropping the database, you will need to kill the connected spids. This can be tedious, so an option to force close all connections and then drop your database that usually works for me is:
use [master];
ALTER DATABASE [foo] SET OFFLINE WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [foo] SET ONLINE;
DROP DATABASE [foo];
By taking the database offline with rollback immediate, I force all connections closed and rollback any open transactions. Now, I could drop it while it is offline, but if I do the database files will remain on the file system. Dropping a database online will remove the database files, so I bring it back online before I drop it.
There is no option in SQL Server.
you can use only use query to manipulate other databasees otherwise you don have any options.
you can detach it just by using another database . for example in Microsoft sql sever management you can use the test database that already exists

Sybase ASE DDL_Prevent

My question is about Sybase ASE 15.3 version database.When our database checked by outsource database professionals for securtiy control,
they were noted that problem :
"It was noted that DDL_PREVENT trigger control restricting DDL
commands in database was not established in your database. Only
database administrator accounts and deployment application account
(such as TCDEPLOY) should be allowed to execute DDL commands in
trigger."
I know "there is DLL_PREVENT mechanism in Oracle Or MSSQL".Is there any method for Sybase?
How can i solve this problem?
Thank You
According to Sybase the following are not supported in triggers:
SQL statements that are not allowed in triggers
Since triggers execute as part of a transaction, the following
statements are not allowed in a trigger:
•All create commands, including create database, create table, create
index, create procedure, create default, create rule, create trigger,
and create view
•All drop commands
•alter table and alter database
•truncate table
•grant and revoke
•update statistics
•reconfigure
•load database and load transaction
•disk init, disk mirror, disk refit, disk reinit, disk remirror, disk
unmirror
•select into
That covers most of your DDL. If there are other commands that you want to restrict, you will likely have to do it through revoking the permssions to users or groups. See Managing User Permissions in the Sybase Administration Guide.
The links are to the Sybase ASE 15.5, not 15.3, but I don't believe there were changes to these areas between these versions.

How to fetch data from a different sql server database without having access?

I have two databases A and B in same SQL Server instance.. I need to write a trigger -- After update of a table in database B it will fetch data from few tables of database A and then insert data in some table of database B .. The issue is the user who will be accessing the database B does not have access to database A .. If I write a trigger with 'sa' account, will it work when the user inserts some data in database B? Also let me know the scenario what would I have to do if database A is in a different SQL Server?
It can work, but you have to do a few things to get there. Here's the easiest way (though not necessarily the best):
Set the owners of both Databases to 'sa'.
Turn on CROSS-DATABASE chaining for both databases.
Turn on TRUSTWORTHY for the source database (B).
Edit the Trigger and add WITH EXECUTE AS OWNER before the FOR clause.
Note that while this works, it has significant security considerations (particularly #2 and #3). Here is a link that explains this and some other methods and some of the security issues: http://msdn.microsoft.com/en-us/library/ms188304.aspx

Resources