SQL 在表格中显示约束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1837793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:37:56  来源:igfitidea点击:

Displaying the constraints in a table

sqloracleconstraintssqlplus

提问by Michael

Hello I am trying to display the constraints in one of my tables but for some reason I get the message no rows selected. Noted below is the table I have created.

您好,我正在尝试在我的一个表中显示约束,但由于某种原因,我收到消息未选择行。下面提到的是我创建的表。

Create table Teams (
   TeamID varCHAR2(4) constraint Teams_TeamID_PK Primary Key,
   TeamName VARCHAR2(40) 
);

This is the code I am using to show my constraints.

这是我用来显示我的约束的代码。

SELECT constraint_name, 
       constraint_type,
       search_condition
  FROM USER_CONSTRAINTS
 WHERE table_name = 'Teams';

I am a rookie so I want to make sure I understand what is wrong. I have tried to drop the table thinking that my constraints did not take - I did not, nor did I receive any errors when I created the table and I am referencing TeamID in another table. So when I try to drop the table I get an error message when is what I was hoping for.

我是菜鸟,所以我想确保我明白出了什么问题。我试图删除表,认为我的约束没有得到 - 我没有,当我创建表并且我在另一个表中引用 TeamID 时,我也没有收到任何错误。因此,当我尝试放下桌子时,我收到一条错误消息,这是我所希望的。

采纳答案by Jeff Hunter

select dbms_mview.get_ddl('TABLE',USER,'TEAMS') from dual;

回答by DCookie

Try this:

尝试这个:

SELECT constraint_name, 
       constraint_type,
       search_condition
  FROM USER_CONSTRAINTS
 WHERE table_name = 'TEAMS';

Unless double-quoted when created, all object names in Oracle are upper case.

除非创建时双引号,否则 Oracle 中的所有对象名称都是大写的。

回答by Tenzin

I personally use:

我个人使用:

SELECT * FROM all_constraints WHERE Table_Name = <TableName>;

回答by user3444871

Use the following code:

使用以下代码:

show create table table_name;

回答by Jeffrey Kemp

If you prefer the CamelCase names, your create table script should have been:

如果您更喜欢 CamelCase 名称,您的创建表脚本应该是:

Create table "Teams" ( 
  "TeamID" varCHAR2(4) constraint "Teams_TeamID_PK" Primary Key, 
  "TeamName" VARCHAR2(40)  
); 

Without double-quotes Oracle helpfully converts all identifiers to uppercase :)

没有双引号 Oracle 有助于将所有标识符转换为大写 :)

回答by Rahul Kharche

Type the table name in upper case in whereclause within the single quotes.

where在单引号内的子句中以大写形式键入表名。

e.g. WHERE table_name = 'TEAMS';

例如 WHERE table_name = 'TEAMS';