
NOT NULL : 用于控制字段的内容一定不能为空(NULL)。
UNIQUE : 控件字段内容不能重复,一个表允许有多个 Unique 约束。
PRIMARY KEY: 也是用于控件字段内容不能重复,但它在一个表只允许出现一个。
FOREIGN KEY: FOREIGN KEY 约束用于预防破坏表之间连接的动作,FOREIGN KEY 约束 2. 也能防止非法数据插入外键列,因为它必须是它指向的那个表中的值之一。
CHECK: 用于控制字段的值范围。
DEFAULT: 用于设置新记录的默认值。
3. not null : 用于控制字段的内容一定不能为空(NULL)。
用法 :Create table MyTable
(
id varchar(32) not null,
name varchar (32)
)
4. Primary Key :也是用于控件字段内容不能重复,但它在一个表只允许出现一个。
在Sql Server、Orcale、MS Access 支持的添加Primary Key语法:
Create table myTB1
(
id nvarchar(32) not null primary key,
name nvarchar(32)
)
1、创建测试表,
create table test_zw(id number, v_date date)
2、插入测试数据
insert into test_zw values(1,20190101)
insert into test_zw values(2,20190102)
insert into test_zw values(3,20190103)
insert into test_zw values(4,20190104)
3、查询表中记录,select t.* from test_zw t
4、编写sql,将v_date字段翻译为中文'日期',select t.*, V_DATE AS '日期' from test_zw t
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)