How to write a SQL statement that adds a field to a data table

Source: Internet
Author: User

If you want to add a field to a datasheet, how do you say it? The following is a description of the SQL statement for adding fields to your table , and hopefully gives you a deeper understanding of SQL statements.

General: ALTER TABLE [ table name ] Add [ field name ] field attribute default default is optional parameter /c15> add field: ALTER TABLE [ table name ] Add field name smallint default 0 Add Number field, Integer, default value 0 ALTER TABLE [ table name ] Add field name int default 0 Add Number field, Long integer, default value is 0    ALTER TABLE [ table name ] Add field name single default 0 Add Number field, one type, default value is 0   ALTER TABLE [ table name ] Add field name double default 0 Add Numeric field, double type, default value is 0 /c11>    ALTER TABLE [ table name ] Add field name Tinyint default 0 Add Numeric field, byte type, default value is 0   ALTER TABLE [ table name ] Add field name text [null] Add Memo Type field,[null] optional parameter    ALTER TABLE [ table name ] Add field name memo [NULL] Add Memo field,[null] optional parameter    ALTER TABLE [ table name ] Add field name varchar(n) [null] increase variable length text Type field size N (1~255)    ALTER TABLE [ table name ] Add field name char [null] increase fixed length text Type field size to 255   ALTER TABLE [ table name ] Add field name datetime default function increment date Type field where function can be now (),date(), and so on, indicating the default value    (The above is the most common, there are other properties, you can refer to the following data type description)Delete field: ALTER TABLE [ table name ] drop field name Modify the size of a variable-length text field:ALTER TABLE [ table name ] Alter field name varchar(N) Delete tables: drop table [ table name ] To Create a table:SQL="CREATE table [ table name ] ([ field 1, and set as primary key ] int IDENTITY (1, 1) not NULL CONSTRAINT PrimaryKey PRIMARY KEY,"&    [ field 2] varchar(+),"&   "[ field 3] Single default 0," &   [ field 4] varchar(+) null,"&   "[ field 5] smallint default 0," &   "[ field 6] int default 0," &   [ field 7] Date default Date(),"&    "[ field 8] int default 1)"   Conn. Execute SQL   a null representation field allows 0 long

How to write a SQL statement that adds a field to a data table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.