AD

Modify the database table structure SQL commands

Add a varchar to a table column:
ALTER TABLE distributors ADD COLUMN address varchar (30);
Remove a field from the table:
ALTER TABLE distributors DROP COLUMN address RESTRICT;
In an operation to modify two existing types of fields:
ALTER TABLE distributors
ALTER COLUMN address TYPE varchar (80),
ALTER COLUMN name TYPE varchar (100);
With a USING clause to an integer field contains the UNIX timestamp into a timestamp with time zone:
ALTER TABLE foo
ALTER COLUMN foo_timestamp TYPE timestamp with time zone
USING
timestamp with time zone 'epoch' + foo_timestamp * interval '1 second ';
Rename the existing field:
ALTER TABLE distributors RENAME COLUMN address TO city;
Change the name of an existing table:
ALTER TABLE distributors RENAME TO suppliers;
To a field to add a non-empty constraint:
ALTER TABLE distributors ALTER COLUMN street SET NOT NULL;
Removed from a field in a non-empty constraint:
ALTER TABLE distributors ALTER COLUMN street DROP NOT NULL;
To a table to add a check constraint:
ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length (zipcode) = 5);
Delete a table and all its child restraint inspection of the table:
ALTER TABLE distributors DROP CONSTRAINT zipchk;
Added to the table a foreign key constraint:
ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
To add a table (multi-field) the only constraint:
ALTER TABLE distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, zipcode);
To a table to add a primary key constraint automatically named to note that a table can have only one primary key:
ALTER TABLE distributors ADD PRIMARY KEY (dist_id);
The table to move to another table space:
ALTER TABLE distributors SET TABLESPACE fasttablespace;
标签: column name, database table, table structure, table column, unix, interval, address type, sql commands, time zone, varchar, table space, drop column, unix timestamp, drop constraint, zone 39, check constraint, integer field, column address, address references, child restraint
分类: Database
时间: 2011-05-16

相关文章

  1. postgresql-see table structure (sql commands and methods). to modify the table structure. foreign key

    SQL mode view table structure (table name is a student) mydb = # SELECT a.attnum, a.attname AS field, t.typnam ...
  2. Design of the database table structure

    Article Design of the database table structure 2008-05-29 17:51 As described in this article title, just like ...
  3. Database table structure

    Database table structure and design of the original documents the relationship between entities can be one to ...
  4. UCHome brief description of the database table structure

    UCHome brief description of the database table structure 1: uchome_member / / uchome Member List uid, username ...
  5. Compare two different database table structure

    1, simple method: Use the following SQL statement: SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NU ...
  6. Export the database table structure _ data _

    Before re-entering the command line to enter the mysql directory. bin Directory Execute the mysqldump program ...
  7. informix database table structure derived under

    1) Export the database table structure to a file all db.sql $> Dbschema-d your_database-t all db.sql 2) Exp ...
  8. (R) DB2 database table structure and data export

    http://hi.baidu.com/mylovechangchu/blog/item/b1c3c644f5decb84b3b7dc6b.html DB2 database table structure and da ...
  9. Library management system database table structure (b)

    Library management system are connected to the database table structure (a) I.1 List of tables Name Code Loan ...
  10. Library management system database table structure (c)

    Access library management system database table structure (b) I.1 List of references Name Code Parent Table Ch ...
  11. Library management system database table structure (II)

    Then on the library management system database table structure (a) I.1 List of tables Name Code Loan Table Loa ...
  12. Library management system database table structure (III)

    Access library management system database table structure (II) I.1 List of references Name Code Parent Table C ...
  13. Export oracle database table structure to the word

    Due to the work requirements, write software, operating documentation, but after the software production proce ...
  14. Query the database and table structure (sql server)

    - Displays the name of all databases select name from master.dbo.sysdatabases; If you want to view the user to ...
  15. Sql database table structure changes

    Modify table structure, including: Add fields, delete fields, add constraint, drop the constraint, modify the ...
  16. DatabaseMetaData usage (transfer) method to obtain the database table structure

    DatabaseMetaData usage (transfer) 2008-08-07 at 12:25 1. Be an instance of this object Connection con; con = D ...
  17. Library management system database table structure (a)

    I.1 Description This is done by using a database modeling tool PowerDesign export documentation, library manag ...
  18. Mysql database table structure difference comparison tool

    This tool is used to compare the structure of MYSQL a database, you can compare the difference with another li ...
  19. Common Actions Database Table Structure

    Create a table : create table tablename ( id int not null , name varchar(20), primary key(id,name) ); Create i ...