create schema authorization etz
 create table employees
  (ID char(3),
   NAME varchar(35),
   address varchar(35),
   phone_number char(11),
   department char(11),
   salary money,
   hourly_rate money
  )
 create table customers
 (
  NAME varchar(35),
  address varchar(45),
  phone_number char(11),
  food_plan char(2)
 )
 create table appt_schedule
 (
  appt_date datetime,  --数据类型
  app_time integer,
  appt_dispostion char(4),
  appt_salesman_id char(3)
 )
 grant select,update on employees to hr_department
 grant all privileges on customers to eting_reps,office_clearks
 grant select on appt_schedule to public
 grant select,insert on appt_schedule to eting_reps
go  --加上它create schema authorization etz create table employees
 (
  id char(3),
  name varchar(35),
  address varchar(45),
  phone_number char(11),
  employee_type char(2),
  salary money,
  hourly_rate money
 )
 grant select,update on employees to hr_department create table patients  --少了table
 (
  id integer,
  sponsor_ssan char(11),
  name varchar(35),
  address varchar(45),
  phone_number char(11),
  ailment_codes varchar(120)
 )
 grant select,update on patients to doctors,nurses,clerks
 create table appt_schedule
 (
  appt_date datetime,  --数据类型
  appt_time integer,
  reason_codes varchar(120),
  doctor_id char(3),
  nurse_id char(3),
  referral_doctor_id char(15)
 )
 grant select,update on appt_schedule to public

解决方案 »

  1.   

    服务器: 消息 4604,级别 16,状态 1,行 25
    不存在这样的用户或组: 'hr_department'。
    服务器: 消息 2759,级别 16,状态 1,行 25
    由于前面的错误,CREATE SCHEMA 失败。
    服务器: 消息 4604,级别 16,状态 1,行 15
    不存在这样的用户或组: 'hr_department'。
    服务器: 消息 2759,级别 16,状态 1,行 15
    由于前面的错误,CREATE SCHEMA 失败。我已经创建了hr_department用户了,结果还是不行
      

  2.   

    up
    看你所创建的hr_department用户,是不是该数据库的用户
    小提一下,不知对不对!
      

  3.   


    if not exists(select 1 from master..sysxlogins where name='hr_department')
    exec sp_addlogin 'hr_department'
    if not exists(select 1 from master..sysxlogins where name='eting_reps')
    exec sp_addlogin 'eting_reps'
    if not exists(select 1 from master..sysxlogins where name='office_clearks')
    exec sp_addlogin 'office_clearks'
    if not exists(select 1 from master..sysxlogins where name='doctors')
    exec sp_addlogin 'doctors'
    if not exists(select 1 from master..sysxlogins where name='nurses')
    exec sp_addlogin 'nurses'
    if not exists(select 1 from master..sysxlogins where name='clerks')
    exec sp_addlogin 'clerks'if not exists(select 1 from sysusers where name='hr_department')
    exec sp_grantdbaccess 'hr_department'
    if not exists(select 1 from sysusers where name='eting_reps')
    exec sp_grantdbaccess 'eting_reps'
    if not exists(select 1 from sysusers where name='office_clearks')
    exec sp_grantdbaccess 'office_clearks'
    if not exists(select 1 from sysusers where name='doctors')
    exec sp_grantdbaccess 'doctors'
    if not exists(select 1 from sysusers where name='nurses')
    exec sp_grantdbaccess 'nurses'
    if not exists(select 1 from sysusers where name='clerks')
    exec sp_grantdbaccess 'clerks'go
    --drop table employees
    create schema authorization etz
     create table employees
      (ID char(3),
       NAME varchar(35),
       address varchar(35),
       phone_number char(11),
       department char(11),
       salary money,
       hourly_rate money
      )
     create table customers
     (
      NAME varchar(35),
      address varchar(45),
      phone_number char(11),
      food_plan char(2)
     )
     create table appt_schedule
     (
      appt_date datetime,  --数据类型
      app_time integer,
      appt_dispostion char(4),
      appt_salesman_id char(3)
     )
     grant select,update on employees to hr_department
     grant all privileges on customers to eting_reps,office_clearks
     grant select on appt_schedule to public
     grant select,insert on appt_schedule to eting_repsgocreate schema authorization etz
    /*
     create table employees  --这里怎么又建和上面一样的表??
     (
      id char(3),
      name varchar(35),
      address varchar(45),
      phone_number char(11),
      employee_type char(2),
      salary money,
      hourly_rate money
     )
    */
     grant select,update on employees to hr_department create table patients  --少了table
     (
      id integer,
      sponsor_ssan char(11),
      name varchar(35),
      address varchar(45),
      phone_number char(11),
      ailment_codes varchar(120)
     )
     grant select,update on patients to doctors,nurses,clerks/*--这里又是建和上面的一样的表
     create table appt_schedule
     (
      appt_date datetime,  --数据类型
      appt_time integer,
      reason_codes varchar(120),
      doctor_id char(3),
      nurse_id char(3),
      referral_doctor_id char(15)
     )
    --*/
     grant select,update on appt_schedule to public
      

  4.   

    是需要分别创建两个构架,etz和etn