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