all groups > sql server programming > july 2005 >
You're in the

sql server programming

group:

Enable Identity



Re: Enable Identity John Bell
7/3/2005 12:00:00 AM
sql server programming: Documentation such a the syntax for all statements can be found in Books
Online the latest version can be downloaded at
http://www.microsoft.com/downloads/details.aspx?FamilyID=A6F79CB1-A420-445F-8A4B-BD77A7DA194B&displaylang=en
or at the online version
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_create2_8g9x.asp?frame=true

John


[quoted text, click to view]

Enable Identity scott
7/3/2005 10:53:42 AM
Below is sample code to create a table within DTS. Every time I use such
code, I have to manually edit each table created and set the primary key
field to be an identity type.

Can I change the code below on the causeID field to make it an identity type
with code?



CODE:

CREATE TABLE [myDatabase].[dbo].[myTable] (
[causeID] int NOT NULL,
[causeCode] varchar (3) NULL,
[causeName] varchar (50) NULL
)

Re: Enable Identity scott
7/3/2005 11:35:45 AM
Given fact that the table has identity or primary key field data, how will
this effect existing values? will it reset the 1st record causeID to "1" or
will it maintain the primary key values and just allow the causeID field to
be an identity type?


[quoted text, click to view]

Re: Enable Identity Adam Machanic
7/3/2005 12:07:54 PM
Is this what you want:


CREATE TABLE [myDatabase].[dbo].[myTable] (
[causeID] int IDENTITY(1,1) NOT NULL,
[causeCode] varchar (3) NULL,
[causeName] varchar (50) NULL
)

--
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--


[quoted text, click to view]

Re: Enable Identity scott
7/3/2005 12:25:21 PM
it seems to work, what is syntax for primary key?
[quoted text, click to view]

Re: Enable Identity Hari Prasad
7/4/2005 12:00:00 AM
Hi,

See the syntax:-

CREATE TABLE [myDatabase].[dbo].[myTable] (
[causeID] int IDENTITY(1,1) NOT NULL constraint pk_causeid Primary Key,
[causeCode] varchar (3) NULL,
[causeName] varchar (50) NULL
)



[quoted text, click to view]

AddThis Social Bookmark Button