create table open_table( desk_number char(2), staff_number char(30), primary key (desk_number,staff_number), foreign key (staff_number) references staff, foreign key (desk_number) references desk);
时间: 2024-04-06 15:33:02 浏览: 11
这是一个Oracle数据库创建表的语句,创建了一个名为open_table的表,包含desk_number和staff_number两个字段,其中desk_number字段的类型为char(2),staff_number字段的类型为char(30),同时还为这两个字段添加了一个联合主键(primary key),并且对staff_number和desk_number字段分别添加了外键(foreign key)约束,分别关联了staff表和desk表。
其中,联合主键的作用是保证了desk_number和staff_number两个字段的组合唯一,而外键的作用是保证了open_table表中的staff_number和desk_number字段的值必须在staff表和desk表中存在,以此确保了数据的一致性。
相关问题
create table desk( desk_number char(2), open_time char(30), accommodation char(2), work_number_of_open_time char(30), state char(10), check(state in ('空闲','占用中')), primary key (desk_number));
这是一条 SQL 语句,用于创建名为 desk 的表。该表包含五个字段:desk_number、open_time、accommodation、work_number_of_open_time、state,都是字符类型。其中,desk_number 字段是主键,open_time 字段是开放时间,accommodation 字段是可容纳人数,work_number_of_open_time 字段是在该桌子上工作的员工工号,state 字段表示桌子的状态,它的值只能为 '空闲' 或 '占用中',这个约束由 check 约束实现。这个表的作用可能是记录每个桌子的开放时间、可容纳人数、占用状态等信息。
create table staff (staff_name char(15)not null, staff_sex char(15) not null, staff_number char(30), staff_salary int, staff_phone char(100), primary key(staff_number));
这是一个Oracle数据库创建表的语句,创建了一个名为staff的表,包含staff_name、staff_sex、staff_number、staff_salary和staff_phone五个字段,其中staff_name字段的类型为char(15),不允许为空(not null);staff_sex字段的类型为char(15),不允许为空(not null);staff_number字段的类型为char(30),允许为空;staff_salary字段的类型为int,允许为空;staff_phone字段的类型为char(100),允许为空;同时还为staff_number字段添加了一个主键(primary key)约束,保证了staff_number字段的唯一性。
其中,主键的作用是保证了staff_number字段的唯一性,以此作为该表的唯一标识符。