March 29, 2011 at 12:45 pm
i have table(t1) with 20 attributes i want to compare it with other 10 tables to detect similar attributes between the table(t1) and other tables one by one and for each comparison process i need to know the name of similar attributes and the number of matches
thanks
March 29, 2011 at 3:50 pm
You could start with the following query returning all tables and related columns in a database:
SELECT
t.name AS table_name,
c.name AS column_name
FROM sys.tables t
INNER JOIN sys.columns c
ON t.object_id = c.object_id
March 29, 2011 at 4:08 pm
Using Lutz's query, I would probably through an order by c.name,t.name in there. You might also want to include the datatype and size as well..
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
March 29, 2011 at 5:17 pm
jamalziena (3/29/2011)
i have table(t1) with 20 attributes i want to compare it with other 10 tables to detect [font="Arial Black"]similar attributes [/font]between the table(t1) and other tables one by one and for each comparison process i need to know[font="Arial Black"] the name of similar attributes [/font]and the number of matchesthanks
A quick question on the items highlighted in the quote above, please. Are you really looking for "similar" name which may be spelled differently or are you looking for "exact matches" for the column names?
--Jeff Moden
Change is inevitable... Change for the better is not.
March 30, 2011 at 1:54 pm
hi Lutz
thank you very much , about the the code :
SELECT
t.name AS table_name,
c.name AS column_name
FROM sys.tables t
INNER JOIN sys.columns c
ON t.object_id = c.object_id
this compare the t1 with first table so i have to repeat for the other 9 table how can i use a procedure to repeat the operation for the 10 table at the end the output display the all similar attribute
thank u alot
March 30, 2011 at 2:00 pm
hi Jeff
yes i am looking for exact matches
March 30, 2011 at 2:18 pm
jamalziena (3/30/2011)
hi Lutzthank you very much , about the the code :
SELECT
t.name AS table_name,
c.name AS column_name
FROM sys.tables t
INNER JOIN sys.columns c
ON t.object_id = c.object_id
this compare the t1 with first table so i have to repeat for the other 9 table how can i use a procedure to repeat the operation for the 10 table at the end the output display the all similar attribute
thank u alot
The code as is will return all of the tables in the database. If you change it as I suggested, the results will sort by column name and then table name. This will make it much easier to spot the like tables.
SELECT
t.name AS table_name,
c.name AS column_name
FROM sys.tables t
INNER JOIN sys.columns c
ON t.object_id = c.object_id
Order by column_name,table_name
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply