Jump to content

SQL beginer, have a question


Guest sangoku

Recommended Posts

Hy i have a lithel confusion problem here i use Microsoft SQL 2008 and i have as strange behavior patern, and some problem's i am a beginner, and have some starting probčlems and my boog SQL from begining dosent give me much advise on this one, so im asking you guys if you can tell me.

Ok my absence of experience is at faul i think, i crated a table

USE Accounting

CREATE TABLE Orders

(

OrderID int IDENTITY NOT NULL PRIMARY KEY,

CustomerNo int NOT NULL FOREIGN KEY REFERENCES Customers(CustomerNo),

OrderDate smalldatetime NOT NULL,

EmpleyeeID int NOT NULL

)

and when AFTER i made some changes to the table, i try to execute the following query :

USE Accounting

ALTER TABLE Orders

ADD CONSTRAINT FK_EmployeeCreatsOrder

FOREIGN KEY (EmployeeID) REFERENCES Employees (EmployeeID)

i get the error

--Msg 1769, Level 16, State 1, Line 112

--Foreign key 'FK_EmployeeCreatsOrder' references invalid column 'EmployeeID' in referencing table 'Orders'.

--Msg 1750, Level 16, State 0, Line 112

--Could not create constraint. See previous errors.

BUT the funy thing is it is writen in teh book to write as it is writen above,,,,, when i do it over the SQL menagment studio ovar a diagram IT WORKS, so myy gues is im using a an old book 2005 and useing 2oo8 server,,, were there eny changes which result un failure of this query,,,

MOUST funy thing is, when i delelte tge staded above constrain and recreate it over the given query after i freshly restarted the server (power button on my laptop) the query gets trough,, can somoen hep me?:confused:

2.

When i make a table :

CREATE TABLE OrderDetails

(

OrderID int NOT NULL,

PartNO varchar(10) NOT NULL,

Description varchar (25) NOT NULL,

UnitPrice money NOT NULL,

Qty int NOT NULL

CONSTRAINT FKOrderDetails Primary key (OrderID, PartNO),

FOREIGN KEY (OrderID) REFERENCES Orders(OrderID)

ON UPDATE NO ACTION

ON DELETE CASCADE

)

and, enter some data and want to delete the constrain on delete cascade i know it is handled by FK constrains,,,, but the model gous like this

ALTER TABLE TableName

ADD CONSTRAINT ConstraintName FOREIGN KEY (FieldNameInChildTable)

REFERENCES ParentTable (FieldNameInParentTable)

First question,, the ON DELETE CASCADE handels the whole table,,, so cold somoen give me an example of the name of the constraint PLESE xD^_^

THY in advise...

Link to comment
Share on other sites

Well it is located in "Learn -> C+/C++"...

And in a way MySQL is a prerequisite to maintain/run mangos...

So questions regarding MySQL is not so far off-topic now are they !? :S

Take the "Myisam Vs Innodb"-topic as a example..

It is just related to mangos but have nothing to do with mangos itself...

Link to comment
Share on other sites

Well it is located in "Learn -> C+/C++"...

And in a way MySQL is a prerequisite to maintain/run mangos...

So questions regarding MySQL is not so far off-topic now are they !? :S

Take the "Myisam Vs Innodb"-topic as a example..

It is just related to mangos but have nothing to do with mangos itself...

But here it's Microsoft SQL 2008, so here is not really the place for this *** software.

Link to comment
Share on other sites

  • 3 months later...
Hy i have a lithel confusion problem here i use Microsoft SQL 2008 and i have as strange behavior patern, and some problem's i am a beginner, and have some starting probčlems and my boog SQL from begining dosent give me much advise on this one, so im asking you guys if you can tell me.

Ok my absence of experience is at faul i think, i crated a table

USE Accounting

CREATE TABLE Orders

(

OrderID int IDENTITY NOT NULL PRIMARY KEY,

CustomerNo int NOT NULL FOREIGN KEY REFERENCES Customers(CustomerNo),

OrderDate smalldatetime NOT NULL,

EmpleyeeID int NOT NULL

)

and when AFTER i made some changes to the table, i try to execute the following query :

USE Accounting

ALTER TABLE Orders

ADD CONSTRAINT FK_EmployeeCreatsOrder

FOREIGN KEY (EmployeeID) REFERENCES Employees (EmployeeID)

i get the error

--Msg 1769, Level 16, State 1, Line 112

--Foreign key 'FK_EmployeeCreatsOrder' references invalid column 'EmployeeID' in referencing table 'Orders'.

--Msg 1750, Level 16, State 0, Line 112

--Could not create constraint. See previous errors.

BUT the funy thing is it is writen in teh book to write as it is writen above,,,,, when i do it over the SQL menagment studio ovar a diagram IT WORKS, so myy gues is im using a an old book 2005 and useing 2oo8 server,,, were there eny changes which result un failure of this query,,,

MOUST funy thing is, when i delelte tge staded above constrain and recreate it over the given query after i freshly restarted the server (power button on my laptop) the query gets trough,, can somoen hep me?:confused:

2.

When i make a table :

CREATE TABLE OrderDetails

(

OrderID int NOT NULL,

PartNO varchar(10) NOT NULL,

Description varchar (25) NOT NULL,

UnitPrice money NOT NULL,

Qty int NOT NULL

CONSTRAINT FKOrderDetails Primary key (OrderID, PartNO),

FOREIGN KEY (OrderID) REFERENCES Orders(OrderID)

ON UPDATE NO ACTION

ON DELETE CASCADE

)

and, enter some data and want to delete the constrain on delete cascade i know it is handled by FK constrains,,,, but the model gous like this

ALTER TABLE TableName

ADD CONSTRAINT ConstraintName FOREIGN KEY (FieldNameInChildTable)

REFERENCES ParentTable (FieldNameInParentTable)

First question,, the ON DELETE CASCADE handels the whole table,,, so cold somoen give me an example of the name of the constraint PLESE xD^_^

THY in advise...

EmpleyeeID != EmployeeID, Problem solved. 90% of my programming issues are typos and mislaid semicolons.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use