Oracle 主键、联合主键的查询与创建

--查询某个表是否有唯一主键

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = ‘P‘ and au.table_name =‘表名‘

--查询某个表是否有联合主键

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = ‘U‘ and au.table_name =‘表名‘

--创建唯一主键

alter table 表名 add constraint pk_table primary key(id); --pk_table 是指 主键的名称,而括号里的 id是指表的唯一主键

--创建联合主键

alter table 表名 add constraint ak_table unique(name,age,sex); --ak_table 是指 联合主键的名称,而括号里的 name,age,sex是指表的联合主键

时间: 2024-08-23 19:18:58

Oracle 主键、联合主键的查询与创建的相关文章

HIBERNATE一对一双向外键联合主键关联

HIBERNATE一对一双向外键联合主键关联: 一. 创建主键类:这个主键必须实现serializedable接口和重写其中的hashCode方法和equals方法:为主键类添加一个叫做@Embeddable的注解和为实体类添加一个叫做@EmbeddabledId的注解

Hibernate(5)—— 联合主键 、一对一关联关系映射(xml和注解) 和 领域驱动设计

俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习!涉及的知识点总结如下: One to One 映射关系 一对一单向外键(XML/Annotation) 一对一双向外键关联(XML/Annotation) 联合主键 一对一单向外键联合主键(Xml/Annotation) 一对一组件关联(XML/Annotation) 理解组件 领域驱动设计——自动生成数据库脚本 一对一关系的小结 一些出错问题的总结 自动生成数据库脚本 一般在项目开发过程中,我们的习惯是先建好数据库和表,然后在进

Hibernate学习笔记_联合主键

复合主键(联合主键):多个字段构成唯一性. 一,xml方式 1. 将联合主键的属性提取出来,重新编写一个StudentPK类(原Student类中的id,name要删除 并新加入属性“StudentPK”) //StudentPK .javapackage com.bjsxt.hibernate; public class StudentPK implements java.io.Serializable{ private int id; private String name; public

hibernate里联合主键composite-id映射,查询单个主键的问题(转)

今天项目中遇到这个问题,搞了大半天,我郁闷...hibernate里联合主键配置(多个字段一起作为主键) <class name="com.cskj.hibernate.map.BbWjjc" table="bb_wjjc" schema="dbo" catalog="wjgl">        <composite-id name="id" class="com.cskj.hi

hibernate里联合主键composite-id映射,查询单个主键的问题

今天项目中遇到这个问题,搞了大半天,现在记录下来hibernate里联合主键配置(多个字段一起作为主键) <class name="com.cskj.hibernate.map.BbWjjc" table="bb_wjjc" schema="dbo" catalog="wjgl"> <composite-id name="id" class="com.cskj.hibernate

Hibernate 查询排序与联合主键映射

1.查询排序 (1)数据库排序(推荐) <map order-by="name ase" > <!--name的升序,降序desc--> session.createQuery(" ").uniqueResult() //返回唯一的对象,前台对象只有一个 <set order-by="name asc"> (2)内存排序 <set sort="natural" > sort属性值

ORACLE: 查询(看)表的主键、外键、唯一性约束和索引

ORACLE: 查询(看)表的主键.外键.唯一性约束和索引 1.查找表的所有索引(包括索引名,类型,构成列) select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 表名 2.查找表的主键(包括名称,构成列): select cu.* from user_co

Hibernate笔记③--集合映射、组合映射、联合主键、查询案例

lazy 懒加载 默认为proxy ? 继承映射 discriminant column="type" type="string" ? 集合映射 生成表的语句: public class DbCreate { ????public static void main(String[] args) { ????????Configuration cfg=new Configuration().configure("/hibernate.cfg.xml"

JPA联合主键@EmbeddedId使用详解附查询例子

花了2个小时的时间解决这个问题,网上资料太少,记录下 详情看源文件TBicPrmCompute,TBicPrmComputePK package com.isoftstone.core.domain; import java.io.Serializable; import javax.persistence.*; /** * The persistent class for the T_BIC_PRM_COMPUTE database table. * */ @Entity @NamedQuer