Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to select the table data just by knowing table name and primary key value in ms sql
Posted
Comments
Prasad Khandekar 21-May-13 2:55am    
Use SELECT * FROM TABLE WHERE PK_FIELD_1 = VALUE_1 AND PK_FIELD_2 = VALUE_2 .... This is assuming that you know the PK fields else you will have to use table metadata to figure out PK columns and then use them in the SELECT. See this link (http://blog.sqlauthority.com/2009/07/17/sql-server-two-methods-to-retrieve-list-of-primary-keys-and-foreign-keys-of-database/)
Sunasara Imdadhusen 21-May-13 3:25am    
Hi Prasad,
Please add your answer into Answer box instead of putting inside comment.
gvprabu 21-May-13 3:25am    
hi, u can try with dynamic query...
Maciej Los 21-May-13 11:22am    
What have you done so far? Where are you stuck?
RedDk 21-May-13 15:32pm    
Loads of information in "SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USEAGE", in deference to PK's comment; this is the actual constraint catalog. Whereby the key value can be linked to a queriable table.

SELECT * FROM KNOWN_TABLE_NAME FROM PRIMARYKEYCOLUMN = 2


YOU CAN DO IT LIKE THIS.
 
Share this answer
 
see this syntax
SQL
Select * from TableName Where PrimaryKeyColumnName = PrimaryKeyColValue

example
SQL
select * from tblEmployee where EmployeeId = 1

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900