Table not visible but accessible in SQL Server - sql

I am using SQL Server 2016 Management Studio, and I encounter something that I haven't seen before and I probably just need some explanation no technical coding involved.
So I was working on some query and need to find tables and usually I check Object Explorer and directly right click table for the first 1000 records. I was joining my claims table with another table for amounts paid column, and I couldn't locate my second table.
I could use select * to get the columns of the table, but it is not visible in my object explorer. Not sure if I am blocked from viewing, but this is my first time seeing it.
I am showing you where my claims table ends and right after it is the Communication table.

Just for an official answer (answers were given in OP comments):
The "table" you can't find is actually a View and can be found in the Views subfolder under the Database.

Related

SQL where statement thousands of values

I have a spreadsheet with 12290 unique reference numbers on that I need to find any payment transactions against.
For a handful id just manually do this. But for a large number like this what would be the best way?
Can I reference a notepad file in a query in anyway?
Thanks,
This is a bit long for a comment.
Although you could put the values into a giant in statement, I would recommend that you load the data into a separate table. That table can have the reference number as a primary key. You can then use a query (join or exists) to get matching values.
This also has the nice side effect that you have the reference numbers in the database, so they can be used for another purpose -- or archived so you can keep track of what your application is doing.
While using #Gordon Linoff's answer.
To upload data there are various methods.
As in the main comments ie. writing a formula in XL and copying that and run the script in Management Studio (I would keep that in a permanent table to avoid doing the same in the future, if the list is not going to be changed often.) and also I wouldn't recommend this for 12000 records, but for less than 100 records it is OK.
Using Import Export wizard of Management Studio
Create a table to hold that data and open that in Management Studio, in Edit mode and copy-paste data to the table.

Find location of a cell's value without knowing table or column name in a sql server database

I need to find a certain table of data but I do not know the name of the table or the columns in it. I have the data in the table at hand. The database is huge do not have the patience it manually go through and look. Is there a query that can be used to search through each of the thousands of tables searching for an exact value that I have.
Having been working as a system admin on systems I did not develop this is an issue I face frequently. Here is how I approach it:
1) Is there a test system and a UI you can insert the values from? If so, do a profile trace or extended events to see where the data is going.
2) Is there a data dictionary for the product you can look through and hopefully find the table location?
3) The hardest way is to use information_Schema.columns and information_schema.tables and make educated guesses as to what the table might be named and review the data in it and see if you have it right or not.

Sql database versus document database?

Small introduction:
I've tried to develop my project with sql database, entity framework, linq.
I have table 'Users' and for example i have list of user educations. I ask myself: 'How much educations user can have? 1, 2, 10...' ? And seems at 99% of cases not more than 10. So for such example in sql i need to create referenced table 'Educations'. Right? If i need to display user educations and user i need to join above mentioned tables... But what if user have 10 or even more collections with not more than 10 items in each? I need to create 10 referenced tables in sql? And than join all of them when i need to display? For better performance i've created denormized tables with shape of data that i need to show on ui. And every time when user was updated, i need to update denormilized structure.
Now i redeveloped my project to use document database(MongoDB). And i've created one document for User with all 10 collections inside.
May be i've lost something? But seems document database win here. It's very fast and very easy to support. +1 to document database.
So, what is your opinion about what better to use document database or sql database?
When I should use document database and when sql?
This article has suggestions on when to use NoSQL DB's. Also this

SQL Server 2005: Audit random record deletion

This may seem like a dumb question, but I'm in a head-> wall situation right now.
I work on a massive ERP application in which the SQL Server 2005 database is updated by multiple disparate applications. I'm trying to figure out where the deletes in a particular table are originating from.
I tried using the Profiler but I'm not able to filter the event types enough to be able to identify the errant SP because there are so many hits to the database every second from various quarters. Also the Profiler seems more directed to finding DDL changes or Object DROP type actions.
I'm simply trying to answer the question: What Stored Proc. or SQL query caused a record to be deleted from Table X?
What tool should I use? I was hoping to avoid something like Trigger based Auditing. Or is the Profiler the best tool for this sort of investigation? Or are third-party tools the only resort?
Please provide any helpful links you can because I'm relatively unfamiliar with this topic.
Finding the culprit with profiler could be like finding a needle in a haystack, especially on a busy system; if you can't find it with filters like edosoft suggests, try to minimize the noise by eliminating statments with writes=0, filter by application name, filter by textdata not like '%select%'; you should be able to get it narrowed down.
If you're really desperate, you could deny delete permission to all users on the table and wait for the phone to ring.
You could also run occassional SELECT COUNT(*) on the table into a work table with timestamps and try to correlate any drops in record counts to other activity.
You could use SQL Profiler for this, but you need to filter the results. To monitor DELETE statements select "RPC:Starting" and "SP:Starting" events and apply a filter on the TextData column: "TextData LIKE '%DELETE%FROM%'".
-Edoode

Strategy for identifying unused tables in SQL Server 2000?

I'm working with a SQL Server 2000 database that likely has a few dozen tables that are no longer accessed. I'd like to clear out the data that we no longer need to be maintaining, but I'm not sure how to identify which tables to remove.
The database is shared by several different applications, so I can't be 100% confident that reviewing these will give me a complete list of the objects that are used.
What I'd like to do, if it's possible, is to get a list of tables that haven't been accessed at all for some period of time. No reads, no writes. How should I approach this?
MSSQL2000 won't give you that kind of information. But a way you can identify what tables ARE used (and then deduce which ones are not) is to use the SQL Profiler, to save all the queries that go to a certain database. Configure the profiler to record the results to a new table, and then check the queries saved there to find all the tables (and views, sps, etc) that are used by your applications.
Another way I think you might check if there's any "writes" is to add a new timestamp column to every table, and a trigger that updates that column every time there's an update or an insert. But keep in mind that if your apps do queries of the type
select * from ...
then they will receive a new column and that might cause you some problems.
Another suggestion for tracking tables that have been written to is to use Red Gate SQL Log Rescue (free). This tool dives into the log of the database and will show you all inserts, updates and deletes. The list is fully searchable, too.
It doesn't meet your criteria for researching reads into the database, but I think the SQL Profiler technique will get you a fair idea as far as that goes.
If you have lastupdate columns you can check for the writes, there is really no easy way to check for reads. You could run profiler, save the trace to a table and check in there
What I usually do is rename the table by prefixing it with an underscrore, when people start to scream I just rename it back
If by not used, you mean your application has no more references to the tables in question and you are using dynamic sql, you could do a search for the table names in your app, if they don't exist blow them away.
I've also outputted all sprocs, functions, etc. to a text file and done a search for the table names. If not found, or found in procedures that will need to be deleted too, blow them away.
It looks like using the Profiler is going to work. Once I've let it run for a while, I should have a good list of used tables. Anyone who doesn't use their tables every day can probably wait for them to be restored from backup. Thanks, folks.
Probably too late to help mogrify, but for anybody doing a search; I would search for all objects using this object in my code, then in SQL Server by running this :
select distinct '[' + object_name(id) + ']'
from syscomments
where text like '%MY_TABLE_NAME%'