Tuesday, March 27, 2012

Export database as SQL scripts - Primary key

This is what I did to generate the SQL Scipt of my database in EM (SQL
Server 2000):
- Right click the database
- All Tasks
- Generate SQL Sripts
- Options tab, check the 'Script PRIMARY keys, FOREIGN keys, defaults, and
check constraints.
However, the output script does not define the primary key of my tables.Hi Alan
"Alan T" wrote:
> This is what I did to generate the SQL Scipt of my database in EM (SQL
> Server 2000):
> - Right click the database
> - All Tasks
> - Generate SQL Sripts
> - Options tab, check the 'Script PRIMARY keys, FOREIGN keys, defaults, and
> check constraints.
> However, the output script does not define the primary key of my tables.
>
Have you checked at the end of the file, there should be a load of ALTER
TABLE statements that add primary keys and foreign keys. Fo example in the
pubs database the first ALTER TABLE statement I get is
ALTER TABLE [dbo].[authors] ADD
CONSTRAINT [DF__authors__phone__78B3EFCA] DEFAULT ('UNKNOWN') FOR [phone],
CONSTRAINT [UPKCL_auidind] PRIMARY KEY CLUSTERED
(
[au_id]
) ON [PRIMARY] ,
CHECK ([au_id] like '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]'),
CHECK ([zip] like '[0-9][0-9][0-9][0-9][0-9]')
GO
John|||Yes, thanks.
The ALTER statements are at the bottom.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:EF1CD898-1644-4ADA-BFD4-C184C1A63436@.microsoft.com...
> Hi Alan
> "Alan T" wrote:
>> This is what I did to generate the SQL Scipt of my database in EM (SQL
>> Server 2000):
>> - Right click the database
>> - All Tasks
>> - Generate SQL Sripts
>> - Options tab, check the 'Script PRIMARY keys, FOREIGN keys, defaults,
>> and
>> check constraints.
>> However, the output script does not define the primary key of my tables.
> Have you checked at the end of the file, there should be a load of ALTER
> TABLE statements that add primary keys and foreign keys. Fo example in the
> pubs database the first ALTER TABLE statement I get is
> ALTER TABLE [dbo].[authors] ADD
> CONSTRAINT [DF__authors__phone__78B3EFCA] DEFAULT ('UNKNOWN') FOR [phone],
> CONSTRAINT [UPKCL_auidind] PRIMARY KEY CLUSTERED
> (
> [au_id]
> ) ON [PRIMARY] ,
> CHECK ([au_id] like '[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]'),
> CHECK ([zip] like '[0-9][0-9][0-9][0-9][0-9]')
> GO
> John
>

No comments:

Post a Comment