How to set identity cache in SQL Server 2014 - tsql

I want to turn identity cache off in SQL Server 2014 - how to that?
I tried the following command
ALTER DATABASE SCOPED CONFIGURATION
SET IDENTITY_CACHE = OFF
I am doing so to make the auto increment work without increment by 1000 on restart

Related

OPENJSON not available on SQL Server 2016 with compatibility level set to 130

I am attempting to use OPENJSON in a database that is running on SQL Server 2016, and get the following error when running this simple test query (which works fine on a different 2016 database)
select * from OPENJSON('{ "test": "test" }')
Invalid object name 'OPENJSON'.
I know about the compatibility level settings, but that doesn't seem to be the case on this database. It's compatibility level is already set to 130. This particular database was migrated from an old 2008R2 database. Is there something else we need to do to access the OPENJSON function?
EDIT
As a test, I created a new empty database on the same database server, and the above query works fine. So the database server doesn't seem to be the issue, it's something related to the one database we migrated.
If it matters, I'm connected as the SA account.
The database's reported compatibility level is 130 from both SSMS gui and by running SELECT compatibility_level FROM sys.databases WHERE name = 'MyDB';
For no reason other than to test, I ran ALTER DATABASE MyDB SET COMPATIBILITY_LEVEL = 130 , and now everything works. I don't know what would cause that.
EDIT
I think I know what caused the weird behavior now. The database that was exhibiting this behavior is a dev database that is created every single morning via replication from the prod database. After some more researching, the prod database was not set to compatibility level 130, but rather 100. I'm thinking that when replication occured and restored the dev DB from the prod log files, even though the dev db was set to 130, something was mismatched between the two. I've since upped prod to 130 as well and all should be good going forward.

SQL Developer 18.3: set alternative schema for individual connections automatically

I'm using several connections in SQL developer to connect to different Oracle databases. For some connections I have to change the schema to that of another user. This can be done is several ways
By using: alter session set current_schema = <otheruser>;
The drawback is that I have to enter this for every connection I want to open and with a different <otheruser> for each connection.
Using the global connection startup script in Preferences > Database > Filename for connection startup script. The drawback of this method is that SQL Developer uses the same global startup script and runs it for every connection I open. Probably trying to set a non existing schema in most -but one- connections.
Is there a way to automatically set the default schema on connecting to a database for individual connections?
Connection Schema
conn_1 Leave current schema unchanged for this connection
conn_2 Change current schema to <schema_A> for this connection
conn_3 Leave current schema unchanged for this connection
conn_4 Change current schema to <schema_B> for this connection
conn_5 Change current schema to <schema_C> for this connection
A solution will be very helpful.
No, that is not a feature. We assume when you define the connection, you are using the schema that you want to work with.
The tool is VERY connection driven - using alter session set current schema will work with queries you run in a SQL Worksheet, but won't have any effect for the rest of the tool, say browsing your tables in the Connection navigation tree.
Now, if you have PROXY connect privs, you could set up your connection to actually connect to your 'default' schema via proxy.
I show how here

Database MSDB can not be opened

I have got this problem in local instance of SQL Server 2008 R2 on my machine. There are several databases on this instance. But I am not able to see any of them from the object explorer.
I am able to query my databases from the new query window. But not able to see any of them.
Whenever I try to explore the databases I get this error :
Database 'msdb' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information. (Microsoft SQL Server, Error: 926).
I have tried
Refreshing the connection
Reconnecting the connection
Restarting the service Sql Server (MSSQLSERVER).
Restarting the SQL Server Management Studio
Restarting my machine
I have also tried combinations of above, but nothing works.
My operating system is Windows 7 Ultimate (64 bit).
SQL Server Management Studio Version is 10.50.2500.0.
I found my answer in this link.
EDIT : Including both the solutions from link because of possible Linkrot in future.
Login with sa account, for both the solutions.
Solution 1
Open new query window
EXEC sp_resetstatus 'DB_Name'; (Explanation :sp_resetstatus turns off the suspect flag on a database. This procedure updates the mode and status columns of the named database in sys.databases. Also note that only logins having sysadmin privileges can perform this.)
ALTER DATABASE DB_Name SET EMERGENCY; (Explanation : Once the database is set to EMERGENCY mode it becomes a READ_ONLY copy and only members of sysadmin fixed server roles have privileges to access it.)
DBCC checkdb('DB_Name'); (Explanation : Check the integrity among all the objects.)
ALTER DATABASE DB_Name SET SINGLE_USER WITH ROLLBACK IMMEDIATE; (Explanation : Set the database to single user mode.)
DBCC CheckDB ('DB_Name', REPAIR_ALLOW_DATA_LOSS); (Explanation : Repair the errors)
ALTER DATABASE DB_Name SET MULTI_USER; (Explanation : Set the database to multi user mode, so that it can now be accessed by others.)
Solution 2
In Object Explorer --> The opened connection item --> rightclick --> Stop
Open Control Panel --> Administrative Tools --> Services
Select Sql Server (MSSQLSERVER) item from services --> rightclick --> Stop
Open C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Move MSDBData.mdf & MSDBlog.ldf to any other place
Then Copy this Files Again from new place and put it in older place
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
In opened connection in object Explorer --> rightclick --> Start
Then Refresh DataBase.
Then you can Detach the MSDB File
The 2nd solution worked for me.
Note : I had to get "msdb" database mdf and ldf files from another working machine to get it working.
What instantly fixed my issue was to replace existing MSDBData.mdf & MSDBlog.ldf files
in C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA. I got these 2 files copied from another working machine, Stopped the SQL service running in my machine, removed the above existing 2 files from their location and added the new 2 copied. Once I restarted the service , issues has been fixed.
Try this
Set the database into single user mode:
Alter database dbname set single_user
Now set the database into emergency mode:
Alter database dbname set emergency
Repair missing log file or corrupted log file with data loss.
DBCC CHECKDB ('dbname', REAPIR_ALLOW_DATA_LOSS)
Now set the db in multi user mode;
Alter database dbname set multi_user
You may loss the data by using this command. It also depends on client's approval. To avoid this you may use some other dedicated software ( As Mentioned here ) to recover from suspect mode.

Are there any system tables auto update in postgresql when postgresql server startup?

I want to use Postgresql 9.2.2 to store my applications' data. I had to
build a trigger wich should based on Database level( When the database startup , this trigger will fired and executed.), Are there any tables auto update when postgresql server startup, in this way i could create a trigger on this table when server startup!
Thanks a lot and best regards!
You can't create triggers on system tables.
Two options occur to me:
Do something on application startup, not database startup.
Add a "psql" call to the end of the pg-server startup script.

postgresql.conf max_prepared_transactions doesn't work

I opened up my postgresql.conf file in the postgres data folder and changed the value of max_prepared_connections to a non-zero value.
However, every time I try using a "PREPARE TRANSACTION 'foo';"command, I get an error saying that max_prepared_connections is set to zero.
Am I doing anything wrong? I just want to be able to use the prepare transaction command.
You must restart the PosgreSQL server after changing this parameter.
go to place where postgresql is installed... in windows , go to
C:\Program Files\PostgreSQL\9.5\data\postgresql.conf
open and then search for "max_prepared_transactions" and uncomment it.
and then set max_prepared_transactions = 1
zero disables the feature
(change requires restart)
Note: Increasing max_prepared_transactions costs ~600 bytes of shared memory
per transaction slot, plus lock space (see max_locks_per_transaction).
It is not advisable to set max_prepared_transactions nonzero unless you
actively intend to use prepared transactions.
after that type services in start menu and search for postgresql and stop the service from left top corner. then restart this service.
then restart the jboss server .
I would like to add that there can be a file C:\Program Files\PostgreSQL\10\share\postgresql.conf.sample which has the same structure as Files\PostgreSQL\9.5\data\postgresql.conf. So, you should also change max_prepared_transactions in that file.
Run following Query e.g. ALTER SYSTEM SET max_prepared_transactions = 100;
Restart Service
Validate by running following Query :- SHOW max_prepared_transactions;