Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,, plz help me

i want to list schema tables and select any table to display its data and can edit and delete data from selected table

thanx
Posted
Updated 18-Dec-11 13:42pm
v2

1 solution

You can use the following query to select and display the table names of the database
SQL
-- This is for SQL Server Database
SELECT *
FROM information_schema.tables
WHERE table_type = 'BASE TABLE'

Once you get the lists of table you can pass the selected table name to the following query to get the list of records.
SQL
SELECT *
FROM TableName -- TableName will be one of the tables from the list. E.g Customers

The delete and update commands are a little bit tricky. You may need to know the primary key of the table.However the update also depends on which columns are going to be updated.
Here is how to list only the primary key columns of the table.
SQL
Exec sp_primarykey TableName -- TableName will be one of the tables from the list. E.g Customers

Here is how to list all columns of the table.
SQL
SELECT 
* FROM sys.columns WHERE object_id = OBJECT_ID(TableName) -- TableName will be one of the tables from the list. E.g Customers

Once you get the list of primary key and the rest of columns you will build your where statement string
For Delete Delete SQL Statement[^]
SQL
DELETE 
FROM TableName 
WHERE Criteria -- Criteria depends of the primary key and the corresponding records E.g pk1='1' AND pk2='2'

For Update Update SQL Statement[^]
SQL
UPDATE TableName
SET ColumnsList -- Columnslist with corresponding list values col1='1' ,col2='2' ...
WHERE Criteria -- Criteria depends of the primary key and the corresponding selected record E.g pk1='1' AND pk2='2'

This is basically what you need to do. There may be little additional work and tune ups.
 
Share this answer
 
v3
Comments
shms_rony 18-Dec-11 19:05pm    
thanks very much
i passed the selected table name in session and get table data
but i can't delete or update table

if you can write update command for any table of these
Wonde Tadesse 18-Dec-11 19:35pm    
Updated
shms_rony 18-Dec-11 19:42pm    
thanks very much for your useful answer

but i want you to write full update command and delete command because i tried but not sucessful

i have test tomorrow morning and i tired from thinking
Wonde Tadesse 18-Dec-11 19:48pm    
For further, read the links that I provided in my answer
shms_rony 18-Dec-11 19:44pm    
Can i contact you on your mail??

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