Jump to content

sangoku

Members
  • Posts

    1
  • Joined

  • Last visited

    Never
  • Donations

    0.00 GBP 

Everything posted by sangoku

  1. 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 ^_^ THY in advise...
×
×
  • 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