加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle建表并设置ID为自动增长

发布时间:2020-12-12 14:03:02 所属栏目:百科 来源:网络整理
导读:CREATE TABLESPACE shoppingDATAFILE ' D:oraclemypcoradataorclshopping.dbf ' SIZE 20M AUTOEXTEND ON ;create user shopping -- 创建 用户 用户名identified by shopping -- 密码 密码字符 default tablespace shopping -- 默认表空间 表空间名tempo
CREATE TABLESPACE shopping
DATAFILE 'D:oraclemypcoradataorclshopping.dbf' SIZE 20M 
AUTOEXTEND ON ;

create user shopping --创建 用户 用户名
identified by shopping --密码 密码字符
default tablespace shopping --默认表空间 表空间名
temporary tablespace shopping; --临时表空间 表空间名


-- 赋予权限
grant connect to shopping with admin option;

-- 角色
grant DBA to shopping with admin option;

使用sql plus登陆管理员帐户,给shopping用户授DBA权限

grant dba to shopping;

以下为设置ID自动增长步骤:

1、建表

2、建序列

3、建触发器

插入自动增长ID

INSERT INTO TABLE_NAME(ID)
VALUES(bill_SEQ_ID.NEXTVAL);

注意点:后来我又遇到个问题,因为我的那个表中有字段数据是空,实际表字段设计的是不可为空,我是用insert请句插入的数据“NULL”,所以在插入自动增长ID的时候报错:

修改表字段勾选 可为空,除非ID外,其它字段都可为空,如果不为空,那么字段数据里面要确实不是NULL才可以


转自:https://www.cnblogs.com/sincoolvip/p/5910751.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读