To change the DEFINITION of a table (not the data in the table): Use ALTER TABLE
Depending on how to defined the table, there are different ways that you can do it:
If you have defined constraint names (eg you added the NOT NULL constraint by using:
ALTER TABLE [tablename] ADD CONSTRAINT [constraint name] CHECK ([columnname] NOT NULL);)
then you can simply drop the associated constraint:
ALTER TABLE [tablename] DROP CONSTRAINT [the constraint name that belongs to the NOT NULL column];
If the constraint does not have a name (or you do not know the name), you can try redefining the entire table:
ALTER CREATE TABLE [tablename] (
[columnname1] [columntype1] {any constraints like PRIMARY KEY, etc},
...
)
In this method, you put all columns that was in the db before in the statement, along will all constraints that were defined. The table will be changed to exactly what you have redefined. To drop the NOT NULL constraint, you just don't put the keyword NOT NULL in at the end of the column definition.
The second method does not work in most database implementations, but is specified in the SQL standard.
2007-11-27 08:20:12 補充:
References:
http://www.mckoi.com/database/SQLSyntax.html#3http://ugweb.cs.ualberta.ca/~c391/manual/chapt6.html (specific to Oracle)
2007-11-27 08:21:28 補充:
If you leave out any column in the second method, the column will be deleted!! Be careful!!