-- 声明使用数据库use 数据库;go -- 添加主键(primary key)约束-- 基本语法-- 判断主键约束是否存在,如果存在则删除,不存在则添加if exists(select * from sysobjects where name=主键名) alter table 表明 drop constraint 主键名;go alter table 表明 add constraint 主键名 primary key(列名) use SapDBT;go-- 实际例子 if exists(se…
MySQL 在建表的时候声明字段即可 id int auto_increment primary key not null Oracle 第一步:建立表 drop table t_role; create table t_role ( role_name varchar(255) NOT NULL, note varchar(255) NOT NULL, id number NOT NULL, PRIMARY KEY (id) ); 这里需要注意主键id得是number类型的,如果是int类型将…