ASP obtains the database table name and field name.

Source: Internet
Author: User

On the ASP forum, many users asked how to obtain the database table name, field name, and how to delete the field, so they wrote this article for additional operations.
I am familiar with sqlserver, so I use sqlserver as the column:
<%
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "Server = IP address; provider = sqloledb; database = database name; uid = user name; Pwd = password ;"
%>
Name of the table in the read SQL Server database:
<%
Set rs = conn. openschema (20)
While not Rs. EOF
Response. Write ("Database Name:" & RS (0) & "<br> ")
Response. Write ("Owner:" & RS (1) & "<br> ")
Response. Write ("table name:" & RS (2) & "<br> ")
Response. Write ("Table type:" & RS (3) & "<br> ")
Rs. movenext
Wend
%>
Now that we know the table name, let's take a look at how to operate the table fields.
Assume that the database contains the table [things]. The table fields are ID, thingsname, and thingstype.
Obtain the names of all fields in the table:
<%
Dim I, j, SQL
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from [things] where 1 <> 1"
Rs. Open SQL, Conn, 1, 1
J = Rs. Fields. Count
For I = 0 to (J-1)
Response. Write ("no." & I + 1 & "field name:" & Rs. Fields (I). Name & "<br> ")
Next
%>
Now we understand how to get the field name.
If you want to perform some operations on the obtained field values, this is also possible:
For example, if you want to delete the thingstype field in the table [things], you can
Write as follows:
<%
SQL = "ALTER TABLE [things] Drop column thingstype"
Conn.exe cute SQL
%>
For example, if we want to add a field thingscolor of the varchar type with a length of 20 and a default value of red, the statement is as follows:
<%
SQL = "ALTER TABLE [things] add thingscolor varchar (20) default 'red '"
Conn.exe cute SQL
%>
The above basic operations on fields are implemented in the SQL language. In ASP, with the SQL language, we can do this with sufficient permissions.
More database operations, such as using create to create tables, and using drop to delete tables

Related Article

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.