how do i insert into two table all at once in a stored procedure?

Posted by user996502 on Stack Overflow See other posts from Stack Overflow or by user996502
Published on 2012-11-10T03:22:31Z Indexed on 2012/11/10 5:00 UTC
Read the original article Hit count: 120

Filed under:
|
|

Doing a project for school so any help would be great thank you!

I have two tables how do i insert into two tables? so both tables are linked.

First table called Customer with primary key called CID that auto increments

CREATE TABLE [dbo].[Customer](
    [CID] [int] IDENTITY(1,1) NOT NULL,
    [LastName] [varchar](255) NOT NULL,
    [FirstName] [varchar](255) NOT NULL,
    [MiddleName] [varchar](255) NULL,
    [EmailAddress] [varchar](255) NOT NULL,
    [PhoneNumber] [varchar](12) NOT NULL        
 CONSTRAINT [PK__CInforma__C1F8DC5968DD69DC] PRIMARY KEY CLUSTERED 
(

And a second table called Employment that has a foreign key linked to the parent table

CREATE TABLE [dbo].[Employment](
    [EID] [int] IDENTITY(1,1) NOT NULL,
    [CID] [int] NOT NULL,
    [Employer] [varchar](255) NOT NULL, 
    [Occupation] [varchar](255) NOT NULL,
    [Income] [varchar](25) NOT NULL,
    [WPhone] [varchar](12) NOT NULL,
 CONSTRAINT [PK__Employme__C190170BC7827524] PRIMARY KEY CLUSTERED 
(

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server