IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QX_USERS]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[QX_USERS]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_QX_GROUPMEMBER_EMPLOYEE]') AND type = 'F')
ALTER TABLE [dbo].[QX_GROUPMEMBER] DROP CONSTRAINT [FK_QX_GROUPMEMBER_EMPLOYEE]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[QX_EMPLOYEE]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QX_EMPLOYEE]
GO

create table dbo.QX_USERS (
  PKEY         	       INT		NOT NULL,
  LOGINNAME            VARCHAR(255)	NOT NULL,
  FULLNAME             VARCHAR(255)	NULL,
  PASSWORD             VARCHAR(255)	NULL,
  EMAIL                VARCHAR(255)	NULL,
  USER_TYPE            INT		NOT NULL,
constraint PK_QX_USERS primary key (PKEY)
)

insert into QX_USERS (PKEY, LOGINNAME, FULLNAME, USER_TYPE) values (0, 'admin', 'Administrator', 1);
GO

ALTER TABLE [dbo].[QX_GROUPMEMBER]  WITH CHECK ADD  CONSTRAINT [FK_QX_GROUPMEMBER_EMPLOYEE] FOREIGN KEY([EMPLOYEEGROUP])
REFERENCES [dbo].[QX_USERS] ([PKEY])
GO

UPDATE QX_SYS_PROP SET PROP_VAL = '007' WHERE (PROP_ID = 'DB_CORE_VERSION');
