ADDING A PRIMARY KEY

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Konstantinos Michas (anonymous_at_discussions.microsoft.com)
Date: 05/03/04


Date: Mon, 3 May 2004 02:34:33 -0700

Hello Experts,

I'm a little bit confused about what happening with these
queries.

I'm trying to add a priamary key on my table. The First
Set of queries do not do that, the Second Set does that,
the funny thing is that I don't see a serious reason not
adding my PK with 1st Set of qureies.

--1st
CREATE TABLE Constraints(DB nvarchar(50), Tbl nvarchar
(50), ConsName nvarchar(100), ConsType nvarchar(50), Cons
nvarchar(500)) ON [PRIMARY]
GO
ALTER TABLE dbo.[Constraints] WITH NOCHECK ADD
        CONSTRAINT [PK_Constraints] PRIMARY KEY CLUSTERED
        ([DB],
         [Tbl],
         [ConsName]
        ) ON [PRIMARY]
GO

--2nd
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Constraints]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[Constraints]
GO

CREATE TABLE [dbo].[Constraints] (
        [DB] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1253_CS_AS NOT NULL ,
        [Tbl] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1253_CS_AS NOT NULL ,
        [ConsName] [nvarchar] (100) COLLATE
SQL_Latin1_General_CP1253_CS_AS NOT NULL ,
        [ConsType] [nvarchar] (50) COLLATE
SQL_Latin1_General_CP1253_CS_AS NULL ,
        [Cons] [nvarchar] (500) COLLATE
SQL_Latin1_General_CP1253_CS_AS NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Constraints] WITH NOCHECK ADD
        CONSTRAINT [PK_Constraints] PRIMARY KEY
CLUSTERED
        (
                [DB],
                [Tbl],
                [ConsName]
        ) ON [PRIMARY]
GO

Thanks in advance!



Relevant Pages

  • MaxLocksPerFile Message
    ... alter table queries in a macro. ... increase the settings and what the settings should be? ...
    (microsoft.public.access.queries)
  • Re: Question on choosing primary key; real or arbitrary
    ... "Watch the order of the columns, so you can take advantage of the indexing; ... that is the real trick." ... ALTER TABLE dbo.INVENTORY_DATA1 ... The 3 most common queries will be as follows ...
    (microsoft.public.sqlserver.programming)
  • Re: Table Format
    ... awach wrote: ... don't use the original table anymore. ... You'll have to alter any other queries you've written to work ...
    (microsoft.public.access.forms)
  • Changing header and footer details in queries???????
    ... Reports are simple in design view but queries are what I am interested ... I have not found a way to alter the header information in a query ...
    (microsoft.public.access.queries)
  • Re: Dating Advice
    ... > It's just a pain you know:) ... What, 2 simple queries? ... alter table t1 add d2 as date; ... Thunderbird E-mail and Newsgroups - http://gettbird.com/ ...
    (comp.lang.php)