Monday, October 18, 2010

ADO how to create modify delete list


ADO how to create modify delete list

ASP can be used directly in the program were modified to delete the table set up

And table-related SQL syntax is as follows:

A table: CREATE TABLE expression.

Modify a table: ALTER TABLE expression.

Delete a table: DROP TABLE expression.

The establishment of an index: CREATE INDEX or ALTER TABLE to use the expression.

Delete an index: DROP INDEX expression.

Details are as follows:

CREATE TABLE expression

CREATE TABLE expression, create a new table.

Syntax is as follows:

CREATE TABLE new table (the new field name a field type [(length)] [NOT NULL] [Index 1] [, the new field names 2 field type [(length)] [NOT NULL] [Index 2] [ , ...]] [, CONSTRAINT multifieldindex [, ...]])

Length character types and character length.

Index 1 Index 2 CONSTRAINT clause of the definition of a single field index.

multifieldindex define a multi-field index.

Use CREATE TABLE expression, if a field is designated as NOT NULL, then add in this field records the information content must be valid information.

CONSTRAINT clause in a field set up different restrictions, and can also be used to establish the main index.

You can use the CREATE INDEX expressions, in the existing table to create a primary index or multiple indexes.

Let us look at a code in ASP which uses the SQL command examples.

For example, the following ASP code rs61.asp, [CREATE TABLE student (name TEXT (10), Age INT)] first, a student of the table, including 10-bit length of the TEXT field type the name, age, character and integer types section.

Implementation, use Access to open NtopSamp.mdb file, a student can see the new table.

ALTER TABLE expression

ALTER TABLE expression, modification has been the establishment of a good table.

Syntax is as follows:

ALTER TABLE table (ADD (COLUMN field name field type [(length)] [NOT NULL] [CONSTRAINT index] |

CONSTRAINT multifieldindex) |

DROP (COLUMN field I CONSTRAINT name of multi-field index name))

Use the ALTER TABLE expression, you can use many different methods to alter its existing table:

Use ADD COLUMN add fields to the table.

Use DROP COLUMN to delete a field. To delete only the specified field name.

ADD CONSTRAINT add multiple fields to use the index.

DROP CONSTRAINT to delete multiple fields using the index. Just specify the index immediately after CONSTRAINT name.

Use ADD COLUMN add fields to the table, you must specify the field names, their types, and type and length.

For example, the following example to add a two character length, character type field named gender to the student table:

ALTER TABLE student ADD COLUMN sex TEXT (2)

You can also define an index on this field.

If you have a field to specify the NOT NULL, then add in this field in the record information must be valid information.




[Next]



You can not add or delete more than one field or index.

For example, the following ASP code rs63.asp, [CREATE TABLE student 1 (Name TEXT (10), Age INT)] before a student a the table, then use [ALTER TABLE students 1 ADD COLUMN sex TEXT (2)] an additional two characters in length, called the sex of the character type field to the students a table:

<%

Set conn1 = Server.CreateObject ("ADODB.Connection")

conn1.Open "DBQ =" & Server.MapPath ("ntopsamp.mdb") & "; Driver = (Microsoft Access Driver (*. mdb)); DriverId = 25; FIL = MS Access;" ;

sql = "CREATE TABLE student 1 (Name TEXT (10), Age INT)"

Set a = conn1.Execute (sql)

Response.Write "CREATE TABLE OK
"

sql = "ALTER TABLE students 1 ADD COLUMN sex TEXT (2)"

Set a = conn1.Execute (sql)

Response.Write "ALTER TABLE OK

"

conn1.Close

%>

Implementation, use Access to open NtopSamp.mdb file, students can see a new table to build a name other fields.

DROP expression

DROP expression from a database, delete an existing table, or remove a table from an existing index.

Syntax is as follows:

DROP (TABLE table | INDEX index ON table)

Table must be closed in order to remove the table or the index of this table.

To remove the index, in addition to using the DROP INDEX index ON table, you can also use the ALTER TABLE.

For example, the following ASP code rs62.asp, the first to use [CREATE TABLE student 2 (Name TEXT (10), Age INT)] 2, first create a student table, including the length of 10 characters TEXT type name field, and integer type age field, and then use the [DROP TABLE students 2] remove the student table 2:

<%

Set conn1 = Server.CreateObject ("ADODB.Connection")

conn1.Open "DBQ =" & Server.MapPath ("ntopsamp.mdb") & "; Driver = (Microsoft Access Driver (*. mdb)); DriverId = 25; FIL = MS Access;" ;

sql = "CREATE TABLE student 2 (Name TEXT (10), Age INT)"

Set a = conn1.Execute (sql)

Response.Write "CREATE TABLE OK

"

sql = "DROP TABLE students 2"

Set a = conn1.Execute (sql)

Response.Write "DROP TABLE OK

"

conn1.Close

%>






Recommended links:



Characteristics Of GIS



MTS To MP4



Guide Audio Rippers And Converters



China mobile phone wholesalers why chinese



e-cology in the Pan Micro Series 68



Lubricant between the public and private cloud came Ubuntu 9.10



Firewall And Proxy Servers introduction



Holiday promotion: how to make the cost may change from control



FLV to iPod



Credit "to bear THE blame," Who back?



See Our Court! Within The Wide Sogou Super Rabbit Letter



Huawei's rivals, where Death



H.264 to AVI



Job on the road a few lessons to remember



No comments:

Post a Comment