ASP get database table name, library name, field name method

Source: Internet
Author: User
Tags table name

ASP get database table name, field name

Take SQL Server as an example:

<%
SET conn=server.createobject ("ADODB. Connection ")
Conn.Open "SERVER=IP address; provider=sqloledb;database= library name; uid= user name; pwd= password; "
%>

Read the table name in the SQL Server library:

<%  
Set Rs=conn.openschema   
While not Rs. eof  
Response.Write ("Database name:" & RS (0) & "<br>")   
Response.Write ("Owner:" & Amp RS (1) & "<br/>")   
Response.Write ("Table name:" & RS (2) & "<br/>")   
Resp Onse. Write ("Table type:" & RS (3) & "<br/>")   
Rs. movenext  
wend  
%>

So that we know the table name, let's take a look at how to manipulate the table's fields.
Suppose that there are tables in the database: [Things], the fields in the table: Id,thingsname,thingstype
Get all the field names for 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 & nbsp
J=rs. fields.count  
for I=0 to (j-1)   
Response.Write ("First" & i+1 & "field Name:" & Rs. Fields (i). Name & "<br/><br/>")   
next  
%
OK, now we know how to get the name of the field.
If you want to do something about the value of the field you get, this is OK:
For example, if we want to delete the field thingstype in table [things], we can
write this:
<%  
Sql= ALTER TABLE [things] DROP COLUMN thingstype "  
Conn.execute sql  
%>
Another example we want to add a field th Ingscolor, its type is varchar, length is 20, and the default value is red, as follows:
<%  
Sql= "ALTER TABLE [things] ADD Thingscolor VARCHAR DEFAULT ' Red '   
conn.execute sql  
%>
The basic operation of the above fields is implemented in SQL language, in ASP, With the SQL language, we can complete the

 

More database operations with sufficient permissions, such as create tables, delete tables with drop, and so on.

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.