All,
I have written some SQL code to create a database then 2 tables and after that insert some records into the new tables in the new database.
Everything works if I execute each SQL statement by itself. However, when I put all the SQL statements in one file and try to execute statements in Query Analyzer I get the following error:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'Job_Title'.
Here is the code I have:
CREATE DATABASE Test
GO
CREATE TABLE Test..Job_Title
( Job_Title_Code nvarchar(50) NOT NULL
CONSTRAINT PK_Job_Title_Code PRIMARY KEY NONCLUSTERED,
Job_Title nvarchar(50) NOT NULL,
Exempt_Non_Exempt_Status bit NOT NULL,
Minimum_Salary decimal(11,2),
Maximum_Salary decimal(11,2)
);
CREATE TABLE Test..Employees
(
Social_Security_Number nvarchar (12) NOT NULL
CONSTRAINT PK_SSN PRIMARY KEY NONCLUSTERED,
Last_Name nvarchar (50),
First_Name nvarchar (50),
Address varchar (50),
City nvarchar (50),
State nvarchar (15),
Zip_Code numeric(5, 0) NULL,
Telephone_Area_Code numeric(3, 0) NULL,
Telephone_Number nvarchar (8),
Email_Address nvarchar (50),
Job_title_code nvarchar (50) NOT NULL
CONSTRAINT FK_Job_Title_Code FOREIGN KEY (Job_title_code)
REFERENCES Job_Title(Job_title_code) ON DELETE CASCADE ON UPDATE CASCADE,
Hire_date datetime NULL,
Salary decimal(11,2) NULL
);
'This is where the process fails!!
INSERT INTO Job_Title VALUES ('1', 'Actor', '1', '500000', '10000000');
Thanks in advance for the help!
I have written some SQL code to create a database then 2 tables and after that insert some records into the new tables in the new database.
Everything works if I execute each SQL statement by itself. However, when I put all the SQL statements in one file and try to execute statements in Query Analyzer I get the following error:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'Job_Title'.
Here is the code I have:
CREATE DATABASE Test
GO
CREATE TABLE Test..Job_Title
( Job_Title_Code nvarchar(50) NOT NULL
CONSTRAINT PK_Job_Title_Code PRIMARY KEY NONCLUSTERED,
Job_Title nvarchar(50) NOT NULL,
Exempt_Non_Exempt_Status bit NOT NULL,
Minimum_Salary decimal(11,2),
Maximum_Salary decimal(11,2)
);
CREATE TABLE Test..Employees
(
Social_Security_Number nvarchar (12) NOT NULL
CONSTRAINT PK_SSN PRIMARY KEY NONCLUSTERED,
Last_Name nvarchar (50),
First_Name nvarchar (50),
Address varchar (50),
City nvarchar (50),
State nvarchar (15),
Zip_Code numeric(5, 0) NULL,
Telephone_Area_Code numeric(3, 0) NULL,
Telephone_Number nvarchar (8),
Email_Address nvarchar (50),
Job_title_code nvarchar (50) NOT NULL
CONSTRAINT FK_Job_Title_Code FOREIGN KEY (Job_title_code)
REFERENCES Job_Title(Job_title_code) ON DELETE CASCADE ON UPDATE CASCADE,
Hire_date datetime NULL,
Salary decimal(11,2) NULL
);
'This is where the process fails!!
INSERT INTO Job_Title VALUES ('1', 'Actor', '1', '500000', '10000000');
Thanks in advance for the help!