PDA

View Full Version : Can't create table from script



beegeebluebo
03-31-2010, 02:27 AM
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

Bob Phillips
04-01-2010, 03:54 AM
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)

beegeebluebo
04-01-2010, 04:46 AM
Thanks but says Database 'HR' does not exist

Tommy
04-01-2010, 05:16 AM
Since you are already connected to the database HR wouldn't it just be: CREATE TABLE Emp ?