Monday, March 26, 2012

forcing string value in table

Hi just wondering if there is a way to have a script that creates a table
write in a desired string for the first table entry?
I have an application that I am allowing the de-activation of a record. I
could not allow a delete since this could result in an orphan record. So
basically the table at startup (when first created) would look like
****************************
* pri key * varchar (20)*
****************************
* 1 * Not Active *
****************************
the application would add records to the table as it is used.
Paul G
Software engineer.
Paul, I'm not clear on what you need.
if not exists (select 'x' from information_schema.tables where table_name =
'mytable' and table_type = 'base table')
create table mytable (id int identity(1,1), status varchar(20))
if not exists (select 'x' from mytable)
insert into mytable (status) select 'Not Active'
Is this close?
Also, do you not have foreign key constraints defined in your data model?
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:4F1222EF-14CF-49C4-B5E7-6F40E3CEE138@.microsoft.com...
> Hi just wondering if there is a way to have a script that creates a table
> write in a desired string for the first table entry?
> I have an application that I am allowing the de-activation of a record. I
> could not allow a delete since this could result in an orphan record. So
> basically the table at startup (when first created) would look like
> ****************************
> * pri key * varchar (20)*
> ****************************
> * 1 * Not Active *
> ****************************
> the application would add records to the table as it is used.
>
> --
> Paul G
> Software engineer.
|||Hi thanks for the response. Its primary key is a foriegn key in another
table, this is why I can not delete a record. I also have a few constraints,
below is from Query analyzer script object. Just would like to put in for
the first record the string "Not Active" so perhaps what you listed should
work.
CREATE TABLE [DML$POC_T] (
[POC_ID] [int] IDENTITY (1, 1) NOT NULL ,
[POC_Name_VC] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
CONSTRAINT [PK_DML$POC_T] PRIMARY KEY CLUSTERED
(
[POC_ID]
) ON [PRIMARY] ,
CONSTRAINT [IX_DML$POC_T] UNIQUE NONCLUSTERED
(
[POC_Name_VC]
) ON [PRIMARY]
) ON [PRIMARY]
GO
"Armando Prato" wrote:

> Paul, I'm not clear on what you need.
> if not exists (select 'x' from information_schema.tables where table_name =
> 'mytable' and table_type = 'base table')
> create table mytable (id int identity(1,1), status varchar(20))
> if not exists (select 'x' from mytable)
> insert into mytable (status) select 'Not Active'
> Is this close?
> Also, do you not have foreign key constraints defined in your data model?
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:4F1222EF-14CF-49C4-B5E7-6F40E3CEE138@.microsoft.com...
>
>

No comments:

Post a Comment