Book a Demo

Author Topic: Database generation code comments  (Read 5635 times)

m0

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Database generation code comments
« on: August 15, 2008, 01:41:05 am »
Hello, I  have two questions :)

I have set my database to be SQL Server 2000 and For a simple table it has created a trigger and stuff like that which I don't understand why...

Code: [Select]
CREATE TABLE ns_menu_module (
      id int NOT NULL,
      name char NOT NULL,
      order_ int NOT NULL
)

;
CREATE TRIGGER ns_menu_module_id_INC
  NO CASCADE BEFORE INSERT ON ns_menu_module
  REFERENCING NEW AS tbl
  FOR EACH ROW
  SET (tbl.id) = (SELECT VALUE(MAX(id),0) + 1 FROM ns_menu_module)

;

ALTER TABLE ns_menu_module
      ADD CONSTRAINT UQ_ns_menu_module_name UNIQUE (name)
;
ALTER TABLE ns_menu_module
      ADD CONSTRAINT UQ_ns_menu_module_order_ UNIQUE (order_)
;
ALTER TABLE ns_menu_module ADD CONSTRAINT PK_ns_menu_module
PRIMARY KEY (id)

;


If doing it manually, I would just do the following:
Code: [Select]
CREATE TABLE ns_menu_module (
      id int IDENTITY NOT NULL,
      name char NOT NULL,
      order_ int NOT NULL,
      PRIMARY KEY(id),
      UNIQUE(name),
        UNIQUE(order_)
)

I understand it created the alter tables for constraints after,  but why did it create a trigger instead of naming it an IDENTITY column?


My other question is about Database Code Generation, I only see Generate DDL once I right click on the table from Design View. I don't see a Generate DDL on the whole Database Model. So if I have 5+ tables that I am designing, or even the whole application database design, It would take me time to right click each table and generate ddl (3 clicks) for each table.

Is there a way to generate all of them at once? I tried selecting all of them but the generate DDL is not visible.

Thanks!
« Last Edit: August 15, 2008, 01:41:39 am by m0interactive »

m0

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Database generation code comments
« Reply #1 on: August 16, 2008, 12:55:02 am »
It is all good now, the generate DDL for database was in a different file menu (not what I assumed it was) Need to select model.

And I reimported my Model from XML into SQL Server 2005 and I see the Identity column now.

thanks though