Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Danny4003
Starting Member
40 Posts |
Posted - 2006-12-29 : 16:04:32
|
I used the following script to create a table in SQL 2000 and gave me an error is there a reason why SQL 2000 doesn't accept this code or am I just leaving OUT an Important Piece Thanks in Advanced,Danny D.Create Table Works (Editor_ID int Primary Key Identity(1,10), First_Name char(30), Last_Name char(40), Phone char(12), Publisher_ID int, KEY publisher_idx (Publisher_ID), CONSTRAINT Publishers_FK1 FOREIGN KEY (Publisher_ID) REFERENCES Publishers (Publisher_ID)) |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2006-12-29 : 16:22:16
|
KEY publisher_idx (Publisher_ID) -- what is this? this is a syntax errorEditor_ID int Primary Key Identity(1,10) -- change to Editor_ID int Identity(1,10) Primary Key, |
 |
|
Danny4003
Starting Member
40 Posts |
Posted - 2006-12-29 : 16:27:43
|
Thats what I want to know what is the KEY for it throws me an error alsoDanny |
 |
|
ramoneguru
Yak Posting Veteran
69 Posts |
Posted - 2006-12-29 : 17:39:25
|
It throws an error because SQL does not recognize that keyword 'KEY'.In any RDBMS you need to specify which keys do what in order to maintain integrity (relational integrity). There are 2 choices, primary and foreign. From the SQL manual:KeysThere are two kinds of keys. A primary key is a set of columns from a table that are guaranteed to have unique values for each row of that table. A primary key is also called a primary key constraint, because it effectively constrains the values you can add to the table: it prevents you from adding a row to the table whose primary key columns are all equal to the corresponding values of some other row in that table.A foreign key is a correspondence between a set of columns in one table and the set of primary key columns in some other table. When discussing foreign keys, the two participating tables are sometimes called the foreign-key table and the primary-key table. A foreign key is also called a foreign key constraint because it constrains table rows: it ensures that any row you add to the foreign-key table has a corresponding row in the primary-key table. That is, it requires that any row added to the foreign-key table have values in the foreign-key column that correspond to the respective values of the primary key columns for some row in the primary-key table.--ramoneguru |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-12-29 : 18:20:55
|
See CREATE TABLE in Books Online for the correct syntax and examples. |
 |
|
|
|
|
|
|