Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 'HASREP'.
FOREIGN KEY HASREP (CUST_REP),
(1) T-SQL doesn't allow you to name your foreign keys.
(2) You have a COMMA *after* that and before the word REFERENCES. No. Big mistake.
(3) No idea where you came up with "SET DELETE".
And, by the way, there is no such data type as INTE
RGER, which is what you coded.
Maybe you should read the documentation???
http://msdn.microsoft.com/en-us/library/aa258255(SQL.80).aspx
So...
Code:
CREATE TABLE CUSTOMERS
(
CUST_NUM INTEGER NOT NULL,
COMPANY VARCHAR(20) NOT NULL,
CUST_REP INTEGER,
CREDIT_LIMIT MONEY,
PRIMARY KEY (CUST_NUM),
FOREIGN KEY (CUST_REP) REFERENCES SALESREP(CUST_REP) ON DELETE CASCADE
)
But you could do this more simply.
Code:
CREATE TABLE CUSTOMERS
(
CUST_NUM INTEGER NOT NULL PRIMARY KEY,
COMPANY VARCHAR(20) NOT NULL,
CUST_REP INTEGER REFERENCES SALESREP(CUST_REP) ON DELETE CASCADE,
CREDIT_LIMIT MONEY
)
Really, it would help to *carefully* read those docs and then follow what they say. I'm guessing that you are converting this code from some other DB, given your use of "SET NULL" which is not at all appropriate for SQL Server.
Continuing, looking at your other errors:
Code:
CREATE TABLE OFFICERS
(
OFFICE INTEGER NOT NULL PRIMARY KEY,
CITY VARCHAR(15)NOT NULL,
REGION VARCHAR(10) NOT NULL,
MGR INTEGER REFERENCES SALESREPS(MGR) ON DELETE CASCADE,
TARGET MONEY,
SALES MONEY NOT NULL,
)
CREATE TABLE SALESREPS
(
EMPL_NUM INTEGER NOT NULL PRIMARY KEY
NAME VARCHAR(15) NOT NULL,
AGE INTEGER,
REP_OFFICE INTEGER REFERENCES OFFICES(REP_OFFICE) ON DELETE CASCADE,
TITLE VARCHAR(10),
HIRE_DATE DATETIME NOT NULL,
MANAGER INTEGER REFERENCES SALESREPS(MANAGER) ON DELETE CASCADE,
QUOTA MONEY,
SALES MONEY NOT NULL
)
I don't know what to do about your ORDERS table, because I have no idea what "ON DELETE RESTRICT" is supposed to mean. It has no meaning at all in SQL Server.
Anyway, when you change from one version of SQL to another, it pays to learn the new dialect.