USE <database, sysname, Swisspeddose_Superset__00>
GO

/*
*/

-- drop table
IF OBJECT_ID('<table_name, sysname, TBL>', 'U') IS NOT NULL
  BEGIN
	DROP TABLE <table_name, sysname, TBL>
  END
GO

-- create table
CREATE TABLE <table_name, sysname, TBL>
	(
		<table_Key, sysname, CoTbl> int NOT NULL,

		Nvar nvarchar(x) NOT NULL,
		Inte int NOT NULL,

		Db_InsDt smalldatetime NOT NULL CONSTRAINT DF_<table_name, sysname, TBL>_DbInsDt DEFAULT (getdate()),
		Db_InsUser nvarchar(50) NOT NULL CONSTRAINT DF_<table_name, sysname, TBL>_DbInsUser DEFAULT (right(suser_sname(),(50))),
		Db_UpdDt smalldatetime NULL,
		Db_UpdUser nvarchar(50) NULL,

		CONSTRAINT PK_<table_name, sysname, TBL> PRIMARY KEY CLUSTERED(<table_Key, sysname, CoTbl> ASC)
	)
GO

-- define update trigger
CREATE TRIGGER ut_<table_name, sysname, TBL> ON <table_name, sysname, TBL> AFTER UPDATE
AS
  BEGIN
	UPDATE <table_name, sysname, TBL>
	SET Db_UpdDt = getdate(),
		Db_UpdUser = right(suser_sname(), 50)
	FROM inserted i
	WHERE <table_name, sysname, TBL>.<table_Key, sysname, CoTbl> = i.<table_Key, sysname, CoTbl>
  END
GO

-- set unique index on Code
CREATE UNIQUE NONCLUSTERED INDEX IX_<table_name, sysname, TBL>__Unique_Code ON <table_name, sysname, TBL> (<table_Key, sysname, CoTbl>)
GO
