Click to See Complete Forum and Search --> : Using Asp to access table fields and records


himverma2005
10-09-2007, 04:06 AM
Hi Once
Whatever I didn't got any response for my previous queries but still I am asking again a new and simple question.
I have to see :
1: Whether a table exists in the server or not
2: If then what fields(column name) are their with names.
3: Last what records does it contains.

All I want to do from ASP script, I am able to see the table directly from the server.
Thanks if you can please reply ASAP.

Chikara
10-10-2007, 12:39 PM
Give me more time and I'll have the answers that you need. Please note it's important to have two dots between db name and the table's name.

All of this was tested and worked in SQL 2000

1.)

IF OBJECT_ID('DATABASENAME..TABLENAME') IS NOT NULL PRINT 'EXISTS' ELSE PRINT 'NO'

This will print up Exists if the table is there and no if it isn't.


2.)

select col_name(object_id('DBNME..TABLENAME'), 1) as 'Column Name'

This will return a column named column name with the name of the 1st column in that table. All you need to do is find out how many columns exist and loop to print up every column name.


3.)

ummmm. . .

select * from TABLENAME

That returns all the records in a table.


This certainly is a precise answer, but it should get you going in the right direction.