The following is a description of the SQL statement for the field name of the query table, and the SQL statement can implement many of the functions, hoping you can learn from the use of SQL statements to gain inspiration.
Select name from syscolumns where id = (select id from sysobjects where type = ' u ' and name = ' corresponding table name ') or select name F Rom syscolumns where id = object_id (' corresponding table name ') use the above SQL statement to enter the corresponding table name can be found in the table's field names, corresponding to the database query whether there is a table statement
The way to determine if a table name exists in a database is
If not object_id (' corresponding table name ') is null print ' exists ' the goal of the field name in this query table is to write a little SQL statement when writing the program, however, there are too many fields in the table, if one copy is too slow, and it is possible to duplicate a field, So using the knowledge of their own database, write a SQL statement directly generate a field name string, for example, I want to write a SELECT statement, you need to generate all the fields in the table:
DECLARE @s varchar (1000) Select @s = IsNull (@s+ ', ', ', ') + [name] from syscolumns where id = object_id (' corresponding table name ') SELECT @ S gets field name already field type, type length
SELECT A.colid as id,a.name as columnname,b.name as datatype,a.length as length from syscolumns a,systypes b WHERE a.id= OBJECT_ID (' corresponding table name ') Anda.xtype=b.xtype and b.name <> ' sysname ' ORDER by a.colid