Implicit PK

Implicit PK

Post by Tobias Butt » Fri, 26 Nov 1999 04:00:00



Shouldn't there be an implicit Primary Key (as combination of all columns)
on tables created WITHOUT a PRIMARY KEY declaration?? If not, what
additional columns are created by SQLS when creating a new table and how can
they be made visible?

The reason for my question is that I'm trying to find out if I can modify
the database design used by a particular application to have PKs on all
tables without affecting the application (which I won't be able to adopt to
a different design).

thx,

Tobias

 
 
 

Implicit PK

Post by Smritee Subb » Fri, 26 Nov 1999 04:00:00


Hi Tobias ,

Please use the stored procedure "sp_help <tablename>"  for information on
all columns created under any particular
table.

Also the following links could be of use to you .

http://msdn.microsoft.com/library/psdk/sql/8_des_04_22.htm
Creating and Modifying PRIMARY KEY Constraints

http://msdn.microsoft.com/library/psdk/sql/7_design_37.htm
How to create or delete a PRIMARY KEY constraint on an existing table
(Enterprise Manager)

Hope it helps .

Regards
Smritee

--
Regards,
Smritee Subba

visitus at www.e-suppportpoint.com


Quote:> Shouldn't there be an implicit Primary Key (as combination of all columns)
> on tables created WITHOUT a PRIMARY KEY declaration?? If not, what
> additional columns are created by SQLS when creating a new table and how
can
> they be made visible?

> The reason for my question is that I'm trying to find out if I can modify
> the database design used by a particular application to have PKs on all
> tables without affecting the application (which I won't be able to adopt
to
> a different design).

> thx,

> Tobias


 
 
 

Implicit PK

Post by KNV » Fri, 26 Nov 1999 04:00:00


He asked for something else.

--

KNV
Check out http://members.tripod.com/~vyaskn/SQLServerRes.html for SQL Server
resources on the net.


> Hi Tobias ,

> Please use the stored procedure "sp_help <tablename>"  for information on
> all columns created under any particular
> table.

> Also the following links could be of use to you .

> http://msdn.microsoft.com/library/psdk/sql/8_des_04_22.htm
> Creating and Modifying PRIMARY KEY Constraints

> http://msdn.microsoft.com/library/psdk/sql/7_design_37.htm
> How to create or delete a PRIMARY KEY constraint on an existing table
> (Enterprise Manager)

> Hope it helps .

> Regards
> Smritee

> --
> Regards,
> Smritee Subba

> visitus at www.e-suppportpoint.com



> > Shouldn't there be an implicit Primary Key (as combination of all
columns)
> > on tables created WITHOUT a PRIMARY KEY declaration?? If not, what
> > additional columns are created by SQLS when creating a new table and how
> can
> > they be made visible?

> > The reason for my question is that I'm trying to find out if I can
modify
> > the database design used by a particular application to have PKs on all
> > tables without affecting the application (which I won't be able to adopt
> to
> > a different design).

> > thx,

> > Tobias

 
 
 

Implicit PK

Post by Michael Hote » Tue, 30 Nov 1999 04:00:00


You would think so.  Yes, they are distinct rows to SQL Server from the
internal standpoint of the storage engine.  However, you have no access to
it.  Even the combination of all columns does not guarantee uniqueness.  The
only way to guarantee that is through a primary key/unique index.

But, you are not out of luck.  You are just looking at a lot of work to
maintain functionality.  If I gave you an object named authors that you
could select, insert, update, and delete from, would you say that is a
table?  Not necessarily.  It could be a view.  This is how you can
accomplish this with zero impact to the application.  You simply reame all
of the tables and add something like an identity or some other identifier
that gets you uniqueness.  You then create a view corresponding to each
table that bears the original table name, but masks out any of the columns
that you have added in.  You have to be extremely careful of parent-child
relationship and will have to code triggers to handle this.  You'll have to
use unique indexes instead of primary keys since a uniqe index can handle a
null if necessary.  I didn't say it would be easy or very clean, but it will
accomplish what you need.

--
Mike
RapidSQL 5.2 review is up: http://www.mssqlserver.com/products
SQL Server resources: http://www.mssqlserver.com
Jokes, general products, and consulting: http://www.mhotek.com
Certification resources: http://www.certfaq.com
SYSOP PASS Discussion Forums: http://www.sqlpass.org

"Aim high. You can never achieve more than you aspire to." - Al Reis
Please direct all replies to the newsgroup unless specifically stated
otherwise.

 
 
 

1. Where is implicit pk index?

I'm under the understanding that when you make a primary key, a unique
index is created by Oracle.  In one form of the syntax, I can't find it.

If I -
SQL> create table junk(a NUMBER primary key, b NUMBER);

Table created.

SQL> insert into junk values (1,2);

1 row created.
etc....
Commit complete.

SQL> select * from user_objects where object_name like '%JUNK%';

JUNK
                                     3649           3649 TABLE
27-JUN-99 27-JUN-99 1999-06-27:17:58:54 VALID   N N

But if I

SQL> create table junk (a NUMBER , b NUMBER);

Table created.

SQL> alter table junk
  2  add constraint junkpk primary key (a);

Table altered.

SQL> select * from user_objects where object_name like '%JUNK%';

JUNK
                                     3651           3651 TABLE
27-JUN-99 27-JUN-99 1999-06-27:18:03:57 VALID   N N

JUNKPK
                                     3652           3652 INDEX
27-JUN-99 27-JUN-99 1999-06-27:18:04:24 VALID   N N

So where is the index in the first form of the syntax?
I also tried dba_segments, dba_objects, dba_indexes, only 1 entry...

- Dc.

2. Exact match inside ambiguous range %...Exactly...%

3. identy PK INSERT into identity PK table???

4. IQ12 - Any large sites out there?

5. Performance: PK Scan or PK Seek

6. SQL Server 2000 - Multiple Instances

7. string PK vs. interger PK

8. SELECT - SQL to browse

9. Stored Procedure: Implicit Transaction?

10. "Implicit transaction" problems

11. Implicit data type conversion

12. INSERT with implicit data conversion

13. Linked server, no dtc, implicit transactions