sql server management plugins - sql-server

Is there some kind of plug in you can get for Microsoft SQL management studio that will:
1) help you format your sql (configuration, so we can get it to match our codeing guidelines)
2) highlight syntax that does not match our coding guidelines
For example if a tool could format the sql so that all selects look like:
SELECT
tbl1.[ColumnX]
tbl2.[ColumnY]
FROM
tbl1
JOIN
tbl2 ON tbl1.[tbl2ID] = tbl2.[ID]
WHERE
tbl2.[ColumnZ] = 'XYZ'
Also if the tool could highlight situations were there are ON ERROR statements and suggest we use TRY CATCH for example.
Hopefully there are plugins that integrate right into the management studio.

Have you looked at SQL Prompt Pro from Red Gate ? It has layout functionality allowing you to layout your SQL to a shared style.
http://www.red-gate.com/products/SQL_Prompt/index.htm

You might want to check out Toad SQL Server beta
Andy

SSMS Tools is free and has a code layout feature.
I don't know of any static code analyzers for SQL Server. I tend just to search the code:
SELECT * FROM sys.sql_modules WHERE definition NOT LIKE '%BEGIN CATCH%'

Related

SQL Server linked server in Management Studio

I have a linked ODBC server (not SQL Server) defined in my SQL Server Management Studio.
The only way I can query it is by using the OPENQUERY command, and that's fine - but it doesn't allow visual query editing or any intellisense.
Is there a way of typing queries against linked servers that behave in the normal way, even an extension?
Try format like this:
<server>.<database>.<schema>.<table>
example:
select foo.id
from databaseserver1.db1.dbo.table1 foo
inner join databaseserver2.db1.dbo.table1 bar
on foo.name = bar.name
You use 3-dot syntax, like this,
<server>.<database>.<schema>.<table>
but it works properly only with linked servers to other instances of MSSQL.

Oracle Database 12 c , SQL Server Translator Is not Translating query

I have installed SQLServer Translators as oracle document require to use 12 c jdbc jar so i replace this jar with jdbc jar.
I have created transport and created profile using sqldeveloper. I have followed steps given in oracle documentation
https://docs.oracle.com/database/121/DRDAA/sql_transl_install.htm#DRDAA29457
Now after completing installation my sqlserver profile has following parameters
Profile_name SQLSERVER_PROFILE
Translator "MON422_QA"."SQLSERVER_TSQL_TRANSLATOR"
Foreign_SQL_syntax True
Translate_new_sql True
Raise_translation_error false
Log_translationerro flase
Trace_translation false
I have installed for migration user and now when I am trying to use for different user I have given execute grant to target user.
But I am unable to translate sql query
Select top 1 * from dual;
Translator is not working as expected. If any additional information is required please let me know I will add the information.
EDIT Query I am trying to run
Select cast ( 5 to NVARCHAR2(50)) from dual;
Should be translated to
SELECT TO_CHAR(5) FROM DUAL:
But it says query terminated undesired parenthesis after NVARCHAR2;
We can see translated queries using sqldeveloper for translator profile being used. But my queries are not being translated at all.
Reference For Translator FrameWork
https://docs.oracle.com/database/121/DRDAA/sql_transl_install.htm#DRDAA29148
The SQL Server translator assumes it is receiving T-SQL or a SQL Server SQL statement in order to translate it.
If you want to use the translation framework to translate an oracle statement to another version of an oracle statement - you can totally do that. But you do not involve the SQL Server translator.
You simply add an entry in your translation profile, a 'template' of the SQL you want translated, and you also provide what you want to come out the other end.
Kerry wrote a very nice blog post demonstrating that here.

How come the Query in Management Portal of Azure didn't work?

I am trying out this exercise - http://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/
Instead of connecting to SQL Server Management Studio 2014, I am using Query in Azure Management Portal. However, I am stuck in Step 7 at a very simple query - "Select * Person". I kept getting error message saying - Invalid object name 'Per'. What was done incorrectly?
I tried but I am unable to repro your issue. You could try open the saved query in a text editor and change the text there, then save and open the file again in the management portal. That may work.
Also, you could try using SSDT https://msdn.microsoft.com/en-us/data/hh297027 for a better development experience.
Please try
SELECT * FROM Person

Index was outside the bounds of the Array. (Microsoft.SqlServer.smo)

I am using SQL Server 2008 R2. It is working fine. But recently, I have changed my hosting server and I came to know that they have installed SQL Server 2012 on Server.
Now, Issue is that after connecting with Server Database through SQL Server 2008 R2, When I click on any table name or Stored Procedure, I am getting error : Index was outside the bounds of the array. (Microsoft.SqlServer.smo)
So, is there any issue from my side or It is from Server Side ??? and How can I prevent this issue ?
Restarting the Management Studio worked for me.
Upgrade your SqlServer management studio from 2008 to 2012
Or
Download the service packs of SqlServer Management Studio and update probably resolve you solution
You can download the SQL Server Management studio 2012 from below link
Microsoft® SQL Server® 2012 Express http://www.microsoft.com/en-us/download/details.aspx?id=29062
For me this problem still exists with SSMS version 2016 (13.0.16100.1).
A decent workaround is to not use the 'Right click' -> 'Add table...' dialog, but simply drag the table you want to add from the Object Explorer, onto the Diagram surface. While dragging the mouse icon changes into an 'add' symbol and the table is added when you release the mouse.
Beats having to close SSMS every time.
Restarted worked!
I found the same error to add new table to my database diagram on sql server 2016, restarted sql server management studio, finally solved.
This is an issue if you are using 2008 management studio tools to connect to a SQL 2012 instance.
I experience this a lot if I am working on one server with SQL 2008, and trying to quickly query another server that is running SQL 2012.
I normally keep my personal workstation on the latest version of management studio (2012 in this case), and am able to administer all servers from there.
The Reason behind the error message is that SQL couldn't show new features in your old SQL server version.
Please upgrade your client SQL version to same as your server Sql version
Solution: Ignore the error
Just to show that the error does not do much in SSMS version 18.9.2, drag the table to be shown in the diagram from the Object Explorer tab and wait for it to finish loading before you start using it.
The suggested causes are now proven to be mostly impossible. I'm running SSMS V17.9.2 against SS 2014 and still have the problem. Memory problems have existed with this tool since at least 2006 when I started using SSMS.
Yes, MS 'wants' to get rid of diagramming but users won't let them. I have a feeling they will never fix any of these issues because they want users to be so fed up with the tool that enough of them quit using it and they can abandon it entirely.
Restarting is still a workaround if you can stand doing so numerous times per day.
you must use new version of Management Studio. And also you will got an error 29506. so you should run as Administrator for setup.
Look this site.
http://shareis.com/post/29506-management-studio-express
I had a similar experience with using SMO via C# with the stack trace:
[1896] System.IndexOutOfRangeException: Index was outside the bounds of the array.
[1896] at Microsoft.SqlServer.Management.Smo.BitStorage.SetBit(Int32 itemIndex, BitIndex bitIndex, Boolean value)
[1896] at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AddObjectPropsFromDataReader(IDataReader reader, Boolean skipIfDirty, Int32 startColIdx, Int32 endColIdx)
[1896] at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ImplInitialize(String[] fields, OrderBy[] orderby)
[1896] at Microsoft.SqlServer.Management.Smo.SqlSmoObject.Initialize(Boolean allProperties)
[1896] at Microsoft.SqlServer.Management.Smo.SqlSmoObject.OnPropertyMissing(String propname, Boolean useDefaultValue)
[1896] at Microsoft.SqlServer.Management.Smo.PropertyCollection.RetrieveProperty(Int32 index, Boolean useDefaultOnMissingValue)
[1896] at Microsoft.SqlServer.Management.Smo.PropertyCollection.GetValueWithNullReplacement(String propertyName, Boolean throwOnNullValue, Boolean useDefaultOnMissingValue)
[1896] at Microsoft.SqlServer.Management.Smo.Information.get_MasterDBPath()
It turned out my versions of the CLR/NCLI/SMO were 10.50.1600.1.
Upgrading them to 10.53.6000.34 fixed it - thus allowing the 2008R2 SMO to do many things with 2012 and 2014 servers.
Get them from the feature pack
https://www.microsoft.com/en-gb/download/details.aspx?id=44272
I found an issue with Diagram and Schema in SQL-Server 2016 that could be useful to the subject.
I was editing diagram (related to, and with lot of tables of, the "sales" schema) and added a new table, BUT forgot to declare it schema, so it was with the default "dbo". Then when I returned to, and opened up, the schema "sales" and tried to add an existent table... Bluf! THAT Triggered exactly the same error described in that thread.
I even tried the workaround (drag the table) but it didn't work. Suddenly I noticed that the schema was incorrect, I updated it, tried again, and Eureka! the problem was immediately away... Regards.
It's very old problem with cashed content. MS planning to remove diagrams from SSMS, so they don't care about this. Anyway, solution exists.
Just close Diagrams tab and open it again. Works with SSMS 18.2.
You have to use latest version with SSMS
You can check latest builds via this page
https://sqlserverbuilds.blogspot.com/

SSMS Object Explorer - Select Top N Rows missing when connected to Azure DB

I just upgraded my SSMS to 2008 R2. I'm missing the option to select the top 1000 rows from a table, like this:
Mine looks like this:
I know how to change the number of rows that are displayed, but the options aren't there at all. I saw that someone submitted a bug for this a few years ago, but there was no workaround, and I'm not sure what to do. Any ideas?
EDIT - Azure Problem?
I just used SSMS to open my local SQL Server, and I get the option to select the top 100 rows. But in my other SSMS instance, the one that is connected to my Azure DB, I don't see it. Is it possibly an Azure limitation?
Based on this answer, I believe it is a limitation of SQL Azure. I have not been able to find any additional information that would allow you to work around the issue.
As of 06/04/2015 MS has published a hotfix to solve this issue.
http://support.microsoft.com/en-us/kb/3011055
"An update is available that enables "Select Top 1000 Rows" option for tables and views of SQL Azure database"
You do not have this option in SSMS while working with SQL Azure, you have to exexute the query yourself ... select top 10000 from tablename
There are few other options as well in SSMS which are not displayed in case of SQL Azure.
This is an excpected behaviour for SQL Azure.
It is now available on SqlServer Mgt Studio 2014.
Check that you have correct values in the SQL Server Object Explorer Settings:

Resources