Is it possible to get Azure database region is sql script? - sql

In Azure database, ServerProperty can get some server property information. But, I want to know the region which database server is running. Is it possible? Can I get this region information with SQL script like below (or something like this):
SELECT SERVERPROPERTY('Region')

Not sure if this can be done from Sql out of the box, but one indirect way could be by using powershell and then calling that powershell script from sql script.
Get-AzureRmSqlServer powershell cmdlet gives detailed information about the servers including region. (Ref)
Then you can call this PS script from SQL as described here.
Not tried it but hope it should work.

Related

Connecting to SQL server through a script and automatically generate data and sent to user as an email

I am working on one concept to reduce the routine work where we query to generate data and sent to client. Can this be possible?
My total query:-
Is there a possibility like to use a script that connects to SQL server and executes a query to generate data and send the data to the user in the form of email with the file attached preferably an .XLS or .XLSX or .csv format.
But the user who is running the script is not having any sql related installed on his machine.
Can someone advise me.
Thank you.
Best regards
You can do this entirely with Sql Server, as an agent job.
If you need this for some reason to run on the end-user's own machine, you can do it via a Powershell script or vbscript that you call from a Scheduled Task. You will need the Sql Server Native Client installed on the machine for this to work, but if that user does anything at all that talks to the database (like use an database driven application) then they likely already have this.
My suggestion is almost similar to the Joel Coehoorn gave you. Also you can find a PowerShell script for emailing in my blog article. As far as I understand you want to automate it all.
Of course you'll have to modify it a little bit, to fit your needs. But the logic is there. If you still have some questions about it, please just ask.
UPDATE
I don't see why not. But since I'm familiar with PowerShell, I'll suggest you the similar solution as described in this article. Pseudo code for sample workflow:
SqlClient.SqlConnection -->
$command.CommandText = $query -->
| Out-File C:\..\result.txt -->
send-mailmessage -Attachments "C:\..\result.txt"
According to MSDN the sqlcmd script supports more complex logic than Transact-SQL scripts. About emailing part - look here. Please note that you'll most probable need the SMTP server details from your admins.

Issuing Teradata SQL Assistant query via script

I use Teradata SQL Assistant to run SQL queries against a DB2 database accessed via an ODBC connection. This is an entirely interactive process whereby I first start the SQL Assistant app, then connect to the correct data source and finally write and execute my query.
What I would like to do is to be able to achieve the same result, i.e. get the result set from a query, but via some sort of script, which would connect to the the data source and run my query.
Is this possible?
Yes this is possible. Install the IBM Data Server Client software appropriate for your version of DB2, then use the DB2 command line processor with the -f option, as described in the manual.

sys.spt_check_constbytable_rowset in SQL Server 2005

I've a list of long running queries on production servers(MS SQL Server 2005) and the most time consuming query is something like this -
SELECT TABLE_CATALOG,TABLE_SCHEMA ...
FROM sys.spt_check_constbytable_rowset
I've been trying to find any object named sys.spt_check_constbytable_rowset in all DBs (including sys DBs) but no luck.
Could anyone please provide some information about this sys.spt_check_constbytable_rowset
This list is provided by the client, so i'm not sure how they've got it- DB trace or something else.
Thanks in advance
I was facing the same issue on my production server.
By looking deeper into it, I found that this type of queries comes from the SSIS package validation process where it is actually validation the objects and other schema information, some time it also executes from different server through linked server.
Thanks

Stored Procedure to generate insert and create SQL for database

How can I move a db from one server to another (I only have access to the database with mylittleadmin). Like the title says, I guess the "easiest" way would be by generating SQL with a stored procedure.
I'm using SQL Server 2008 on both servers.
In the codeplex project Extreme T-SQL Script I have written T-SQL procedures to script the content of tables. I just abandoned its use myself in favor of ssms tools pack, but the later is no option for you.
When using these procedures in SSMS or VS the main problem is that Microsoft has limits on max column width and max length of output from Print-Statements.
I can't predict, which such limits exist when using mylittleadmin.
It depends on which datatypes and which varchar length you are using. Writing scripts that handle special needs is possible.
Further you need something to script the database objects first and it might be difficult to find something for that, as most people just use SSMS for this purpose. sp_helptext might help to script procedures.
In SSMS, you have the ability to copy or move a database from one instance of SQL Server to another. You can right-click on the database in SSMS, choose Tasks and then Copy Database...
Or, of course, you can simply backup the DB and restore on your target server.
(I have no idea what 'myLitleAdmin' is that you referred to)
You dont need to make a stored procedure. The easiest way to do it is by right click on your database -->task-->back up and create a backup.
after that you can restore your database on the other server.
If you have a license for myLittleAdmin then do as their web states. It says
"Purchasing a license gives you unlimited mail support.
Send your request at support#mylittletools.net"
Actually I found out that you could make a backup of the database in myLittleAdmin. The resulting .bak file was then emailed to me as a link.
Thanks for the comments though, voted up some of them :)

See queries that hit SQL

Is there a way using sql 2008 Management Studio to look at the queries that hit the server? I'm trying to debug a program and I get messages like "Incorrect syntax near the keyword 'AND'". Since the queries are being dynamically generated it's a hassle to figure out what is going to the server.
Any help is appreciated!
There is a tool called Profiler that will tell you all information that you'll need. MSDN: http://msdn.microsoft.com/en-us/library/ms187929.aspx
I'm not aware of any method to do this using SQL Server Management Studio, but if you installed SSMS then you probably also installed the SQL Profiler. If you fire that up and run the TSQL_SPs profiler template, you can see every statement that's hitting the database.
Since the queries are being dynamically generated it's a hassle to figure out what is going to the server.
Why not just put the query that's generated into a message box, or print it to the console, or webpage, etc. ??
Trying to catch it at the DB server seems to be the long-way-around to debugging some simple ad-hoc queries.
Go to Management...Activity Monitor in the object explorer.
It's not live though, you will have to refresh it manually.
start up profiler from SSMS (Tools-->SQL Server Profiler), run a trace and select the T-SQL events
One option is to use SQL Server Profiler to run a trace. However, in some shops SQL Server permissions are set so only DBAs can run traces.
If you don't have sufficient rights to run a trace, then another option is to view the network traffic between the application that generates the SQL and box SQL Server is running on. WireShark works great for that.