I know that my question probably don't belong here but I would be really so thankful if someone has the skill for solving this out.  I have recently made several update statements that I shouldn't have done and would like to see their queries with parameters or at least something so I could retrieve the data back manually.   I'm able to access ::fn_dblog(NULL, NULL) and I would like to know if can I see the queries with parameters from there?  It could have been cca 200 statements.   I'm using SQL server 2012.  I don't have backup or query tracing ony my server.
5182
I mistakenly deleted around 2,000,000 records from a remote SQL Server 2008 table.  The server is not granting me access to the backup files on the server side.   Is there any way to get back these records?
61340
What is the difference between SQL batch, T-SQL statement and Remote Procedure Call? How can I tell if part of the T-SQL code is a batch or statement?
15336
In SQL Server 2005, is there a way to find users that either don't exist at the server level (an account that was deleted at server level but wasn't disassociated from databases before it was deleted) or accounts that aren't linked (an account may have been deleted at the server level but not db level, then readded but the db level was never cleaned up).  I've got a very messy server and it would be awesome if there was a query to run to find these.
56719
I would like to gather statistics on the highest run queries in my database.   For that I need to know how I can track queries so I can create views or materialized views to cache the results of the highest run queries since I have a big DB.
34791
This is the announcement post of the Stack Exchange Data Explorer. Its answers were meant to iron out the initial glitches 6 to 8 years ago.  If you have found a bug or need support  today with any of SEDEs features, please ask a new question and tag it with   What does it do? Allows you to run arbitrary SQL queries on the data dumps, and share those queries with your friends. Technical details It is hosted on the Stack Exchange infrastructure , the database is hosted on the same SQL Server version all other sites are hosted on. You can use most of the TSQL commands, even create temporary objects (but not User Defined Functions). The controls used are jQuery based, the grid is  . All query results are cached, so sharing a link to a query will not result in the server going in to a tailspin. The query edit control is a slightly modified  control, I also am considering bespin cause the inter iframe communication is nasty complicated. It gives up nice syntax highlighting for queries. Parameters There is support for parameterized queries, to get it to work name your params like ##this##. For example have a . Query name and description A query can have a name and description, to name it lead with a comment, to describe it continue commenting, for example: -- This is my query name  -- This is my description -- I can span multiple lines  SELECT 1  Anonymous users can initially name a query, but can not change the names of any existing queries. Tutorial There's a  which helps you getting started in writing your own SQL queries. Logging in You can use your openid provider to log in, at the moment once logged in we will track the list of queries you execute (giving you basic history support) Also if there are any params named UserId they will be populated automatically if your EmailHash matches the one on the site being queried. Magic columns If you alias an id column with as [Post Link] it will automatically create a link in the result set to the parent site. Similarly if you alias an id column with as [User Link] it will display a link to the user page. select top 10 * from Posts will show you how tags are done. (Magic columns for images is planned) example (most controversial posts:  ) So what are you waiting for, check it out at  Any feedback would be greatly appreciated. I hope to have the login section working fairly soon and allow voting on the best queries and commenting. Featured Queries At the moment, admins have permission to feature interesting queries on this page , I am looking for better ways to manage the huge query list that is building up.
62975
I'tm trying to show in SQLcmd window the results of these queries:  SELECT SYSDATETIME() AS "date";  PRINT 'EXTRAÍDO POR:' SELECT SUSER_NAME() AS "Owner"  PRINT 'PASSWORD SETTINGS'; exec xp_loginconfig;  PRINT 'PASSWORD SETTINGS'; select * from sys.sql_logins;   And using this command in SQLcmd:  sqlcmd -S myServer -i inputpath -s, -o outputPath(like C:\log.xls) -e   So the sqlcmd output the file and does not show nothing in sqlcmd screen. How can i print these "Print" commands in the sqlcmd screen? (command promt).  When I run it on SSMS works well, like:  (1 row affected) OWNER:  (1 row affected) PASSWORD SETTINGS  (8 rows affected) PASSWORD SETTINGS  I would like to show in the prompt command this, like in the SSMS.  Thanks!
101250
I am lost in a big database and I am not able to find where the data I get comes from. I was wondering if it is possible with SQL Server 2005 to search for a string in all tables, rows and columns of a database?  Does anybody has an idea if it is possible and how?
78798
I have a table structured as so (Simplified)  Name, EMail, LastLoggedInAt   I have a user in SQL Server (RemoteUser) that should only be able to see data (Via a select query) where the LastLoggdInAt field is not null.   It looks like I can do this? Is it possible?
64523
This is a question regarding general DB inner workings, not particular to an implementation or paradigm, though answers for certain technologies are welcome. I am asking if there is a way to listen to what commands the database has received, or something like read an inner log of the database, at least the last changes. I need such a functionality to be able to find if there were changes to a table and if so, read the particular row that has changed. It is assumed changes to the columns are not to happen. I am only a listener of the database, hence I am not able to program triggers.
20251
Our DBA team doesn't verify the backups using the below TSQL (which can easily be done post-backup and takes almost no time, so I don't get why not):  RESTORE VERIFYONLY FROM DISK = 'D:\Backups\LOCATION'   They've had issues in the past, so even though we'd think they'd learn from it, they haven't.  I created a Powershell script to do this because we have about 100+ servers and I just want to run this script against all the backups just to ensure they're valid.  The below script runs correctly (in that it doesn't break or throw errors), I am curious if there's a way to get the printed message back in Powershell that we would normally get in SSMS where it states The backup set on file 1 is valid as verification.  $SqlCon = New-Object System.Data.SqlClient.SqlConnection $SqlCon.ConnectionString = "SERVER=SERV\INST;Integrated Security=true;DATABASE=master"  $baks = Get-ChildItem "D:\Backups\" -Filter *.BAK  foreach ($bak in $baks) {     $SqlCon.Open()     $cd = New-Object System.Data.SqlClient.SqlCommand     $cd.Connection = $SqlCon      $cd.CommandText = "RESTORE VERIFYONLY FROM DISK = @f"     $cd.Parameters.Add("@f", $bak.FullName)     $cd.ExecuteNonQuery()     $SqlCon.Close() }
15483
I'm experiencing an annoying problem with a table named SysMessages in one of our databases. When I run a select statement I don't get the contents of this table, but of the sys.sysmessages view in the master database. A use [DBNAME] doesn't help, nor select * from [DBNAME].dbo.SysMessages.  I'm in the middle of a migration to a newer SQL Server version. In SQL Server 2008 R2 I didn't encounter this problem with this database, but in SQL Server 2016 I'm not able to query my own SysMessages table.  Any help would be greatly appreciated.
87197
Is there a way to log all Microsoft SQL Server queries executed on a certain server, with their respective durations?  I'd like to be able to analyze all queries will a tool like what  does for PostgreSQL. While we're at it: do you know of any such tools?
65478
How can I get the list of available databases on a SQL Server instance? I'm planning to make a list of them in a combo box in VB.NET.
27987
I have a SQL Server 2012 database. I noticed value of Reason for early termination of statement optimization for some queries and all gave Good Enough Plan Found. Now my questions are:   What are all the possible types of  “Reason for early termination of statement optimization”. I did searching for this in msdn but didn’t get a complete list of values. Is there a DMV or extended event to list all queries for which optimization was terminated due to reasons other than Good Enough Plan Found? I referred following two articles which does not list the complete list of possibilities. [Also, they give me different result in my database].
9803
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I have a collection of records, like a List&lt;sObject&gt; or the Trigger.new context variable. I need to query other records that are related to these records either directly or indirectly, and I want to use the related data to make further updates. When I write a query in a loop, like for (Account a : Trigger.new) {     Account parent = [SELECT Name FROM Account WHERE Id = :a.ParentId];     // ... }  I keep hitting Salesforce query limits, and I know this is not best practice. What can I do to avoid this problem and bulkify my code?
123269
Inspired by a StackOverflow question ().  Is there a DBMS that actually supports the = NULL syntax?
56372
I'm working on a request to start logging some additional data for PCI compliance.  I need to log who, when, and what changed on a set of tables.  I set up SQL auditing which would work fine except for the fact that the values of what is being changed is coming through as @1, @2 etc instead of the actual data.  What are my other options for logging the needed information?  CDC does not track who made the change.  This is currently running on SQL Server 2012 but a possible upgrade to 2014 is possible if that would provide a better solution.  Thanks, Tim