Recently, I saw a lot of netizens asked how many netizens asked how to get database table names, field names, and how to delete fields, and add this article. I am more familiar with SQL Server, so SQL Server is column: <% set conn = server.createObject ("adodb.connection") conn.open "server = IP address; provider = SQLOLEDB; Database = library name; UID = User name ; PWD = password; "%> Name name in the SQL Server library: <% set = conn.openschema (20) While NOT RS.EOF response.write (" The database name: "& rs (0) &" < BR> ") Response.write (" Owner: ") Response.write (" Table Name: "& RS (2) &"
") Response.write "Type of Table:" & RS (3) & "
") rs.movenext Wend%> This, we know the table name, now let's take a look at how to operate on the table. Suppose: [Things], the field in the database is: ID, thingsname, ThingsType Get all the field names of 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 = r.fields.count for i = 0 to (J-1) Response.write ("" "" & i 1 & "field name:" & rs.Fields (i) .Name & "
") Next%> well, now we understand how to obtain a field name.
If you want to make some operations for the obtained field value, this is also possible: For example, we want to delete the table [things] in the field Thingstype, you can write: <% sql = "Alter Table [Things] Drop Column Thingstype" conn .execute sql%>, for example, we want to add a field ThingsColor, its type is VARCHAR type, the length is 20, and the default is RED, the method is as follows: <% sql = "alter table [things] add thingscolor varchar (20 DEFAULT 'Red' "Conn.execute SQL%> The basic operation of the field is implemented with SQL language. In ASP, through SQL language, we can complete more database operations as much as enough permissions, such as CREATE Table, use Drop Delete Table, etc. Finally, this person will be shallow, this article will definitely have a mistake, but also hope that everyone criticizes. I also hope that everyone will send me a text message to me, thank you!