SQL Server Add Field issues

Source: Internet
Author: User

Select A.adjustment_id,a.adjustment_code to tmp20161103 from Adjustment_code a

ADJUSTMENT_ID will keep autogrow from the source table

SELECT * FROM tmp20161103

Syntax for adding columns:

ALTER TABLE [table name] add [Field name] field property default [value]

Add column TT, default value is 0

ALTER TABLE tmp20161103 add TT int default 0

inserting row data

Insert into tmp20161103 (Adjustment_code) VALUES (' Ttttt ')

The newly inserted data, the TT column will have a default value of 0

SELECT * FROM tmp20161103

Add one more column

ALTER TABLE tmp20161103 add TTTTT int default 1

Inserting values

Insert into tmp20161103 (Adjustment_code) VALUES (' Ttttt ')

SELECT * FROM tmp20161103

The newly inserted data will have a default value

The following is the Add, delete field reference

Add, delete fields

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-Purpose:

ALTER TABLE [table name] add [field name] field attribute default default value is optional parameter

Add Field:

ALTER TABLE [table name] Add field name smallint default 0 Add Number field, Integer, default value is 0

ALTER TABLE [table name] Add field name Intdefault 0 Increase Number field, long integer, default value is 0

ALTER TABLE [table name] Add field name Singledefault 0 Add Number field, single type, default value is 0

ALTER TABLE [table name] Add field name Doubledefault 0 Add Numeric field, double type, default value is 0

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 field, [NULL] optional parameter

ALTER TABLE [table name] Add field name Memo[null] Add note type 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] Add fixed-length text field size to 255

Alter table[table name] Add field name the datetime default function adds a date field where the 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]

SQL Server 2008 Add, delete field

http://blog.csdn.net/wide288/article/details/14524751

SQL Server Add Field issues

Related Article

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.