在表中显示约束

发布于 2024-08-13 22:00:59 字数 497 浏览 2 评论 0原文

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

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

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

假装不在乎 2024-08-20 22:00:59

试试这个:

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

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

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.

清晰传感 2024-08-20 22:00:59

使用以下代码:

show create table table_name;

Use the following code:

show create table table_name;
分開簡單 2024-08-20 22:00:59

我个人使用:

SELECT * FROM all_constraints WHERE Table_Name = <TableName>;

I personally use:

SELECT * FROM all_constraints WHERE Table_Name = <TableName>;
眉目亦如画i 2024-08-20 22:00:59
select dbms_mview.get_ddl('TABLE',USER,'TEAMS') from dual;
select dbms_mview.get_ddl('TABLE',USER,'TEAMS') from dual;
乜一 2024-08-20 22:00:59

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

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

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

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

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 :)

暮年慕年 2024-08-20 22:00:59

在单引号内的 where 子句中输入大写的表名称。

例如 WHERE table_name = 'TEAMS';

Type the table name in upper case in where clause within the single quotes.

e.g. WHERE table_name = 'TEAMS';

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文