Tag Info

New answers tagged

0

You can find duplicate PKs: select pk_col, count(*) from tab group by pk_col having count(*) > 1 -- multiple rows with the same PK exist Or the actual rows violating the PK: select * from tab where pk_col in ( select pk_col from tab group by pk_col having count(*) > 1 -- multiple rows with the same PK exist ) This returns bad FKs: ...


1

There are many different ways of defining a primary key and I think its there to match with standard SQL. Below are 3 different ways of creating a primary key: create table dept (deptno decimal(2,0) PRIMARY KEY, dname varchar(14), loc varchar(13)); create table dept (deptno decimal(2,0), dname varchar(14), loc varchar(13), constraint pk_dept primary key ...


2

A primary key is an object that lives in the meta data of the database. It will have a name no matter how it is created. The question is will it have a meaningful name that matches your coding standards and that your team can understand at a glance or will it have a meaningless name the the system generates and everyone will continually have to look up? ...


0

Although foreign key names can be anything, it's actually a good practice to follow the convention of putting the table name first. The most important reason for this is that foreign key names must be globally unique (contrarily to index names). So, by following this convention, foreign key names only have to be unique within each table. Personally, I use ...


2

Following @ypercube comment to the question, I came up with this solution: with recursive A as ( select code1, code2 from B where code1 = new.code2 union all select a2.code1, a2.code2 from B a2 join A on a2.code1 = A.code2 ) select * from A where code2 = new.code1 If any records are returned, then new.code2 references new.code1 and ...


3

The schema on the left is your own DDL statement. The schema on the right is a DDL statement generated by your schema comparison tool. The statement on the right shows constraint names for your DEFAULT constraints. Yours does not have them but that does not mean SQL Server allows you to create a nameless constraint. When you do not provide a name ...



Top 50 recent answers are included