23. januar 2001 - 10:46Der er
7 kommentarer og 1 løsning
Lav / slet kolonne i MS SQL
Hvordan laver / sletter jeg enkelte kolonner i allerede eksisterende tables på en MS SQL server via ren ASP kode.. (Jeg har ikke fysisk adgang til serveren.)
Modifies the design of a table after it has been created with the CREATE TABLE statement.
Note The Microsoft Jet database engine doesn’t support the use of ALTER TABLE, or any of the data definition language (DDL) statements, with non-Microsoft Jet databases. Use the DAO Create methods instead.
Syntax
ALTER TABLE table {ADD {COLUMN field type [(size)] [NOT NULL] [CONSTRAINT index] | CONSTRAINT multifieldindex} | DROP {COLUMN field I CONSTRAINT indexname} }
The ALTER TABLE statement has these parts:
Part Description table Name of the table to be altered. field Name of the field to be added to or deleted from table. type Data type of field. size Field size in characters (Text and Binary fields only). index Index for field. See the CONSTRAINT clause topic for more information on how to construct this index. multifieldindex Definition of a multiple-field index to be added to table. See the CONSTRAINT clause topic for more information on how to construct this clause. indexname Name of the multiple-field index to be removed.
Remarks
Using the ALTER TABLE statement, you can alter an existing table in several ways. You can:
Use ADD COLUMN to add a new field to the table. You specify the field name, data type, and (for Text and Binary fields) an optional size. For example, the following statement adds a 25-character Text field called Notes to the Employees table: ALTER TABLE Employees ADD COLUMN Notes TEXT(25)
You can also define an index on that field. For more information on single-field indexes, see the CONSTRAINT clause topic.
If you specify NOT NULL for a field, then new records are required to have valid data in that field.
Use ADD CONSTRAINT to add a multiple-field index. For more information on multiple-field indexes, see the CONSTRAINT clause topic.
Use DROP COLUMN to delete a field. You specify only the name of the field.
Use DROP CONSTRAINT to delete a multiple-field index. You specify only the index name following the CONSTRAINT reserved word. Notes
You cannot add or delete more than one field or index at a time.
You can use the CREATE INDEX statement to add a single- or multiple-field index to a table and you can use ALTER TABLE or the DROP statement to delete an index created with ALTER TABLE or CREATE INDEX.
You can use NOT NULL on a single field or within a named CONSTRAINT clause that applies to either a single field or to a multiple-field named CONSTRAINT. However, you can apply the NOT NULL restriction only once to a field, or a run-time error occurs.
Det er taget fra MSDN Library. Du kan finde det på Microsoft hjemmeside, jeg har ikke lige adressen. Jeg har en offline version i mit udviklingsmiljø...
tak for det... HAr dog helle rikke selv testet det, men tror på det virker... :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.