creating an TSQL Makro for daily usage [duplicate] - sql

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.

Related

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

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.

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%'

To see whether a column of a table is been used somewhere in the database [duplicate]

This question already has answers here:
How can we figure out that a column in my oracle table is being populated/updated by a trigger of another table?
(3 answers)
Closed 5 years ago.
How to check whether a particular column of a table is used in any other object or not in Oracle? For example I have a table EMPLOYEE which has a column BONUS. I need to check whether this column of this table is been used by any other objects like View, Package etc in the database.
You can try the following SQL to check for the table and column used within the object definition
SELECT 1
FROM all_source
WHERE type IN ('PROCEDURE','PACKAGE BODY','FUNCTION')
AND text LIKE '%EMPLOYEE%'
AND text LIKE '%BONUS%';

UPDATE within a table from table name saved in the column [duplicate]

This question already has answers here:
How do I UPDATE from a SELECT in SQL Server?
(38 answers)
Closed 8 years ago.
I have a little problem, but I'm sure it s not really complicated.
It's just hard to find the key word to describe the problem and find a solution
I want to update a column in a table using parameters from this table for a query on an other table.
Example : I have Header + 2 lines
IDSOURCE, IDCIBLE, IDENTIFIANT, TABLE_CIBLE, NOM_ATTRIBUT, NOM_CHAMP_IDENTTIFIANT, NOM_CIBLE
--------------------------------------------------------------------------------------------
DMT_1000, DMT_1000, 1000, [dictionnaire].[dbo].[TABLE_CHAMPS_DATAMART], NOM_CHAMP_DMT, IDENTIFIANT_CHAMP_DATAMART, NULL
DMT_1001, DMT_1001, 1001, [dictionnaire].[dbo].[TABLE_CHAMPS_DATAMART], NOM_CHAMP_DMT, IDENTIFIANT_CHAMP_DATAMART, NULL
And I want to update the last column of each line with something like :
UPDATE
Table
SET
Table.NOM_CIBLE = SELECT table.NOM_ATTRIBUT FROM table.TABLE_CIBLE WHERE table.NOM_CHAMP_IDENTTIFIANT = table.IDCIBLE
FROM
Table
Don't know if it s clear.
Thanks for your help.
This sounds like situation where you could use a cursor. Check out this StackOverflow question How to update a column fetched by a cursor

Possible to exclude or reorder a column from `*`? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
SQL exclude a column using SELECT * [except columnA] FROM tableA?
Is it possible to exclude a column from a select * from table statement with SQL Server?
I have a need for this and this is my only option other than parsing a raw SQL string to get out the required field names (I really don't want to do that).
Just to be bold. When the query is made I do not have access to the list of fields needed from the table but I do know which field I do not need. This is part of a complex multi-part query.
Surely there must be some way even if it's "hackish" such as using table variables or views
My other option is to reorder the columns. My problem is with ExecuteScalar SQL functions which get the first row and first column.
EDIT
I can't add an answer since this is now closed but the way I ended up doing it was like so:
;with results_cte as (
select (calculation) as calculated_column, * from table
)
select * into #temptable from results_cte
where calculated_column<10 /*or whatever*/
alter table #temptable
drop column calculated_column
select * from #temptable
drop table #temptable
Nope. You'll have to build your statement manually or just select *.
No.
Instead, you could check syscolumns to get all of the field names, or (perhaps) SELECT * and ignore that column.
If you use dynamic SQL, you can generate the query from metadata about the table or view (INFORMATION_SCHEMA.COLUMNS) and exclude columns that way. I do this a lot to generate triggers or views.
But there is nothing in the SQL language which supports this.
The best way to handle this would be to select * and then just not present the excluded column to your users in your frontend. As others have noted, SQL has no direct capability of doing an all-columns-except construct.