Querying table fields and stitching code using SQL syscolumns

Source: Internet
Author: User

We do not have to write code to add data, update data, but if a table field too much, the amount of code to write will be increased, such as using StringBuilder splicing Insert SQL statement;

Code that is not technically available can be generated from a code generator, or it can be generated by using SQL as a table field:

1, the following code is to find all the field names in a table

Select name from syscolumns where id=object_id (' Table name ')

2, on the basis of 1 we can arbitrarily splicing our return results, such as we need to be all the fields with commas (of course, can be implemented by SQL recursion, but if the results are no longer logical judgment, you can try the following method faster)

Use the Select name + ', ' from syscolumns where id=object_id (' table name ') statement to execute the result, and then copy the entire column value into EditPlus, and you can get a string of strings as you merge the rows.



3, based on the 2nd step thinking, we can use arbitrary splicing according to demand

Select' _insertsql.append (", '" "+_k3dt. rows[i]["'+name+' "]. ToString () + "" "); ' fromsyscolumnswhereID=object_id(' T_icitem ')



Querying table fields and stitching code using SQL syscolumns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.