dbo.show_doc

Description

Properties

Name Value
File Collation
File Group
Filestream File Group
Is Partitioned

False

Partitioned Column
Partition Scheme
File Groups
Filestream Partition Scheme
Filestream File Groups
Heap

True

Full Text Catalog
Full Text
Compression NONE
Row Count (~) 0
Created 10/1/2007 3:29:34 PM
Last Modified 4/3/2016 12:31:43 AM

Columns

7
Key Name Data Type Length Precision Scale Not Null Identity Rule Default Computed Persisted Description
doc_id int 4 10 0

True

False

False

website_id tinyint 1 3 0

True

False

False

doc_position_id varchar 50 0 0

True

False

False

show_from_date datetime 8 23 3

False

False

False

show_to_date datetime 8 23 3

False

False

False

doc_order smallint 2 5 0

False

False

False

template_id int 4 10 0

False

False

False

Indexes

1
Key Name Columns Unique Type Description
PK__show_doc__33D4B598 doc_id, website_id, doc_position_id

True

Triggers

2
Name ANSI Nulls ON Quoted Identifier ON On Not For Replication Description
tI_show_doc

True

True

AFTER INSERT

False

tU_show_doc

True

True

AFTER UPDATE

False

Foreign Keys

2
Name Columns Description
FK__show_doc__doc_id__71D1E811 doc_id
FK__show_doc__templa__70DDC3D8 template_id

SQL Script

Copy
CREATE TABLE dbo.show_doc (
  doc_id int NOT NULL,
  website_id tinyint NOT NULL,
  doc_position_id varchar(50) NOT NULL,
  show_from_date datetime NULL,
  show_to_date datetime NULL,
  doc_order smallint NULL,
  template_id int NULL,
  PRIMARY KEY NONCLUSTERED (doc_id, website_id, doc_position_id) WITH (FILLFACTOR = 90)
)
ON [PRIMARY]
GO

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER trigger dbo.tI_show_doc on dbo.show_doc for INSERT as
/* ERwin Builtin Mon Oct 01 10:32:44 2007 */
/* INSERT trigger on show_doc */
begin
  declare  @numrows int,
           @nullcnt int,
           @validcnt int,
           @errno   int,
           @errmsg  varchar(255)

  select @numrows = @@rowcount
  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  /* templates R/74 show_doc ON CHILD INSERT SET NULL */
  /* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="templates"
      CHILD_OWNER="", CHILD_TABLE="show_doc"
      P2C_VERB_PHRASE="R/74", C2P_VERB_PHRASE="", 
      FK_CONSTRAINT="R_74", FK_COLUMNS="template_id" */

  if
    /* %ChildFK(" or",update) */
    update(template_id)
  begin
    update show_doc
      set
        /* %SetFK(show_doc,NULL) */
        show_doc.template_id = NULL
      from show_doc,inserted
      where
        /* %JoinPKPK(show_doc,inserted," = "," and") */
  show_doc.doc_id = inserted.doc_id and
        show_doc.website_id = inserted.website_id and
        show_doc.doc_position_id = inserted.doc_position_id and
   
        not exists (
          select * from templates
          where
            /* %JoinFKPK(inserted,templates," = "," and") */
            inserted.template_id = templates.template_id
        )
  end

  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  /* docs R/213 show_doc ON CHILD INSERT RESTRICT */
  /* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="docs"
      CHILD_OWNER="", CHILD_TABLE="show_doc"
      P2C_VERB_PHRASE="R/213", C2P_VERB_PHRASE="R/213", 
      FK_CONSTRAINT="R_213", FK_COLUMNS="doc_id" */

  if
    /* %ChildFK(" or",update) */
    update(doc_id)
  begin
    select @nullcnt = 0
    select @validcnt = count(*)
      from inserted,docs
        where
          /* %JoinFKPK(inserted,docs) */
          inserted.doc_id = docs.doc_id
    /* %NotnullFK(inserted," is null","select @nullcnt = count(*) from inserted where"," and") */
    
    if @validcnt + @nullcnt != @numrows
    begin
      select @errno  = 30002,
             @errmsg = 'Cannot INSERT show_doc because docs does not exist.'
      goto error
    end
  end


  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  return
error:
    raiserror (@errmsg,@errno,1) 
    rollback transaction
end

GO
CREATE OR ALTER trigger dbo.tU_show_doc on dbo.show_doc for UPDATE as
/* ERwin Builtin Mon Oct 01 10:32:44 2007 */
/* UPDATE trigger on show_doc */
begin
  declare  @numrows int,
           @nullcnt int,
           @validcnt int,
           @insdoc_id int, 
           @inswebsite_id tinyint, 
           @insdoc_position_id varchar(50),
           @errno   int,
           @errmsg  varchar(255)

  select @numrows = @@rowcount
  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  /* templates R/74 show_doc ON CHILD UPDATE SET NULL */
  /* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="templates"
      CHILD_OWNER="", CHILD_TABLE="show_doc"
      P2C_VERB_PHRASE="R/74", C2P_VERB_PHRASE="", 
      FK_CONSTRAINT="R_74", FK_COLUMNS="template_id" */

  if
    /* %ChildFK(" or",update) */
    update(template_id)
  begin
    update show_doc
      set
        /* %SetFK(show_doc,NULL) */
        show_doc.template_id = NULL
      from show_doc,inserted
      where
        /* %JoinPKPK(show_doc,inserted," = "," and") */
  show_doc.doc_id = inserted.doc_id and
        show_doc.website_id = inserted.website_id and
        show_doc.doc_position_id = inserted.doc_position_id and
   
        not exists (
          select * from templates
          where
            /* %JoinFKPK(inserted,templates," = "," and") */
            inserted.template_id = templates.template_id
        )
  end

  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  /* docs R/213 show_doc ON CHILD UPDATE RESTRICT */
  /* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="docs"
      CHILD_OWNER="", CHILD_TABLE="show_doc"
      P2C_VERB_PHRASE="R/213", C2P_VERB_PHRASE="R/213", 
      FK_CONSTRAINT="R_213", FK_COLUMNS="doc_id" */

  if
    /* %ChildFK(" or",update) */
    update(doc_id)
  begin
    select @nullcnt = 0
    select @validcnt = count(*)
      from inserted,docs
        where
          /* %JoinFKPK(inserted,docs) */
          inserted.doc_id = docs.doc_id
    /* %NotnullFK(inserted," is null","select @nullcnt = count(*) from inserted where"," and") */
    
    if @validcnt + @nullcnt != @numrows
    begin
      select @errno  = 30007,
             @errmsg = 'Cannot UPDATE show_doc because docs does not exist.'
      goto error
    end
  end


  /* ERwin Builtin Mon Oct 01 10:32:44 2007 */
  return
error:
    raiserror (@errmsg,@errno,1) 
    rollback transaction
end

GO

ALTER TABLE dbo.show_doc
  ADD FOREIGN KEY (doc_id) REFERENCES dbo.docs (doc_id)
GO

ALTER TABLE dbo.show_doc
  ADD FOREIGN KEY (template_id) REFERENCES dbo.templates (template_id)
GO

Depends On

3