Table exists but doesn't appear SQL Server [duplicate] - sql

This question already has answers here:
What is the meaning of "#" in front of a table name in TSQL?
(2 answers)
Closed 12 months ago.
I've used the query
SELECT TOP (1000000) ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS N
INTO #Tally3
and it worked. But I can't find the table #TALLY3 in SQL Server, even after refreshing.
What is weird is that after executing
SELECT *
INTO test
FROM table1
the table test did appear and I was able to see it.
What's even weirder,
SELECT * FROM #TALLY3
works now even though it doesn't appear and SQL Server underlines #TALLY3 in red because it thinks it doesn't exist:
Can someone help me?
Thanks!

That's a #temporary table. It's created in tempdb, not your user database. You're not going to find it in Object Explorer, and it's only visible in the query window that created it. It will disappear when that session ends.

Related

Insert statement from a linked server won't insert into the table. What am I missing here?

I'm using SQL Server 2016 to attempt to insert records from couple of tables located on a linked server. I can run the query and pull the data that I'm looking for, but when I attempted to insert it into the table it runs successfully, but no data is inserted into the SQL Server table. Here's my code;
insert into BTGroup (authorizedgroup, itemno)
select custno, prod
from OPENQUERY(NxtTest, '
select s.custno, p.prod, p.zauthorized
from pub.zics s
join pub.csp p on s.prod = p.prod
where p.zauthorized = 1
')
I feel like I'm missing something obvious here, but I'm new to working with linked servers so I'm a bit lost. Any help is greatly appreciated.
If you didn't get any error message and receive a message like (20 rows affected) in result window so everything is ok.
Check the selected database that contains BTGroup table when you are executing the query or change it to the full address. (e.g. MyDatabase.dbo.BTGroup)

Can I locate tables based on a column value? [duplicate]

This question already has answers here:
Find a value anywhere in a database
(18 answers)
Closed 5 years ago.
I am working without documentation we have a dental system that displays the status of an appointment.
I have to report on who scheduled the appt. and who confirmed. The systems displays this as 'FIRM' and 'FIXED. I have located how they store the person who scheduled the appt. but not who has confirmed it.
But since they use 'FIRM" is there a way I can locate which tables have this value? we are running sql server 2008.
you can find out the table name which have column name like FIRM by using below query -
select * from information_schema.columns where column_name like '%FIRM%'
if you want to know where this column is referred (like in SP , trigger or view) or a or hard coded value is used to display, you can use below query-
select distinct object_name(id) from syscomments where text like '%FIRM%'

creating an TSQL Makro for daily usage [duplicate]

This question already has answers here:
Is there a way to expand the column list in a SELECT * from #Temp_Table in SSMS?
(5 answers)
Closed 6 years ago.
I want to create a Makro for myself that Converts a Star into a list of Columns.
My Question here is: Is there any way to Access the Tool tip that my SQL Server 2014 gives me when I hover over the said Star.
My intention here ist that if i have a Statement like
Select * from #TempTab
join Tab1 on Temp_ID=Tab_ID
join Tab2 on Tab1_ID = Tab2_Tab1_ID
...
the only thing i have to do is pressing a 'Makro' and my Star gets replaced by the current list of Columns
Use SSMS built in option.
Right click your table name in the object explorer then select top 1000 rows.
It gives you all columns with top 1000 records.

Simple SQL statement in MS Access [duplicate]

This question already has an answer here:
MS Access 2010 SQL Select Into Calculated Column Issue
(1 answer)
Closed 6 years ago.
I'm trying what should be a simple task in Access. Basically to create a new table based on a string matching query. The Hazus_Schools table already exists in my database. The Hazus_Public does not, and I'm trying to create it. The PUBLIC field is a calculated column from another field. The following snippet
SELECT * FROM Hazus_Schools INTO Hazus_Public
WHERE Type = "PUBLIC";
Gives me the following error:
Syntax error in FROM clause
Any ideas what is wrong here?
The order of your INTO and FROM is off, see W3schools Select Into
Try the following:
SELECT *
INTO Hazus_Public
FROM Hazus_Schools
WHERE Type = "PUBLIC"

SQL ORDER BY (sequence) [duplicate]

This question already has answers here:
sql ORDER BY multiple values in specific order?
(12 answers)
Closed 9 years ago.
I have a sql statement which I would want to ORDER BY a specific sequence.
SELECT * FROM UserDB ORDER BY [Role]
How can I make it such that the data brought to my GridView table is listed from Admin on the top, follow by User and Guests?
So you want to order by Admin/User/Guest?
Try something like :
SELECT *
FROM UserDB
ORDER BY
CASE Role WHEN 'Admin' THEN 0
WHEN 'User' THEN 1
WHEN 'Guest' THEN 2
END
Does that work for you?
Another option would be to have (or add) a column Sequence to your Role table so you could define the sequence in the table itself - and then just to an ORDER BY Role.Sequence.
This is substantively identical to the question " sql ORDER BY multiple values in specific order? " and I strongly recommend you look at the solutions presented there.