Consulting

Results 1 to 4 of 4

Thread: Can't create table from script

  1. #1

    Can't create table from script

    In SMS created a new database, just the New Database command. I have the attaced script to create a table but it fails with a Schema error. The problem is I can't see where I have to define the schema. I can create a table manually.

    Error
    Msg 2760, Level 16, State 1, Line 1
    The specified schema name "HR" either does not exist or you do not have permission to use it.

    Script
    CREATE TABLE HR.Emp(
    EmpID int NOT NULL,
    FirstName nvarchar(50) NOT NULL,
    LastName nvarchar(50) NOT NULL,
    PhoneNumber nvarchar(25),
    ManagerID int,
    DeptID int NOT NULL,
    Address nvarchar(60),
    City nvarchar(30),
    PostalCode nvarchar(15),
    ProvinceCode nchar(3),
    BirthDate datetime NULL,
    HireDate datetime NULL,
    VacationTime smallint NULL,
    SickTime smallint NULL)


    Many thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,221
    Location
    Try this

    CREATE TABLE HR.dbo.Emp(
    EmpID int NOT NULL,
    FirstName nvarchar(50) NOT NULL,
    LastName nvarchar(50) NOT NULL,
    PhoneNumber nvarchar(25),
    ManagerID int,
    DeptID int NOT NULL,
    Address nvarchar(60),
    City nvarchar(30),
    PostalCode nvarchar(15),
    ProvinceCode nchar(3),
    BirthDate datetime NULL,
    HireDate datetime NULL,
    VacationTime smallint NULL,
    SickTime smallint NULL)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks but says Database 'HR' does not exist

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Since you are already connected to the database HR wouldn't it just be: CREATE TABLE Emp ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •