I have a database that stores the complete details of the employees of a firm. I need to select column names from multiple tables in the database which when executed would provide me the columns required to list specific details. So, I tried the following query which returns the columns of the specified table only.
SELECT TABLE_NAME,COLUMN_NAME
FROM mydatabase.INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME=N'TBLemppersonaldetails'
All the tables have a Column named 'EmployeeId' which can be considered as a primary key. Now, how could i get all required columns from all the tables by avoiding certain columns such as Update Date,Mode that repeats in all the tables. I would prefer using 'Inner Join' to join all the tables. For example consider the tables below:
Table1 Table2
EmployeeId Name Address Mode EmployeeId Gender BloodGroup Mode
---------------------------------------- -------------------------------------------
001 abc No.9,vv 1 001 Male O+ve 1
street,
Considering the example above, I require the columns EmployeeId,Name,Address,Gender,BloodGroup to be listed after the execution of the query while excluding the column named 'Mode' from both the tables. I request you to consider another scenario where the so called 'PrimaryKey' constraint doesn't exist for the 'EmployeeId' Column. PS: I am using SQL Server 2008