Modify Field Defaults and Properties

yuanwen
modifies the existing field attributes in the
table ALTER TABLE table name
ALTER COLUMN field name varchar(500)
-- sqlserver sets the default value of the field when creating a table create table 表(id int,name varchar( 10) default ' Zhang San ', age int )
-- set the default value of the field when adding a field alter table table add sex char( 2) default ' male '

-- set the default value for the existing field in the table alter table Table add constraint DF_age_table default( 20) for age go
-- insert a record to verify insert table (id) values( 1 ) select * from table go There are mainly the following constraints: NOT NULL : The content of the control field must be Cannot be NULL. UNIQUE : The content of the control field cannot be repeated. A table is allowed to have multiple Unique constraints. PRIMARY KEY: It is also used for the content of the control field and cannot be repeated, but it is only allowed to appear once in a table. FOREIGN KEY: FOREIGN KEY constraints are used to prevent actions that destroy connections between tables, FOREIGN KEY constraint 2. also prevents illegal data from being inserted into the foreign key column, since it must be one of the values ​​in the table it points to. CHECK: Used to control the value range of the field. DEFAULT: Used to set the default value for new records.
not null : The content used to control the field must not be NULL. Usage: Create table MyTable ( id varchar( 32 ) not null , name varchar ( 32 ) )

Primary Key : It is also used for the control field. The content cannot be repeated, but only one of it is allowed in a table. Add Primary Key syntax supported by Sql Server, Oracle, MS Access: Create table myTB1 ( id nvarchar( 32 ) not null primary key, name nvarchar( 32 ) )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324608237&siteId=291194637