Welcome to Sign in | Help

Re: relationare intre tabele in SQL

  •  04-22-2008, 4:58 PM

    Re: relationare intre tabele in SQL

    cam asa ar fi in SQL Server 2005

    /* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    BEGIN TRANSACTION
    GO
    COMMIT
    BEGIN TRANSACTION
    GO
    ALTER TABLE dbo.Table1 ADD CONSTRAINT
      FK_Table1_Table2 FOREIGN KEY
      (
      t2_id
      ) REFERENCES dbo.Table2
      (
      id_t2
      ) ON UPDATE NO ACTION
       ON DELETE NO ACTION
      
    GO
    COMMIT


    Am tabelul Table1 cu chiea primara id_t1 (int) si coloana t2_id - nchar(10) si tabelul Table2 care are ca si cheie primara coloana id_t2 - nchar(10) iar scriptul de mai sus face legatura intre id_t2 si t2_id .

    Eu am obtinut scriptul facand legatura intre tabele pe diagrama si folosind optiunea "Generate Change Script" din meniul "Table Designer" inainte sa dau save
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems