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 |
Dufresne
Starting Member
5 Posts |
Posted - 2010-05-09 : 07:37:57
|
Hi , I'm newbie for SQL.I'm stuck with a problemI've following tableAddress ( AddressID TINYINT NOT NULL, CustomerID INT NOT NULL, Address VARCHAR(200) NOT NULL) AddressID and CustomerID are composite Primary Key.CustomerID is Foreign Key to Customer Table.What i want is automatic increment AddressID with same CustomerIDSuppose that , we'll add 3 addreses for customer whose id is 1 and 4 addresses for the customer whose id is 2.So my table shall look likeAddressID CustomerID Address1 1 'Address'2 1 'blabla'3 1 '...'1 2 '..'2 2 '....'3 2 '.....'4 2 '....'AddressId shall increment and automatically become 1 when it's entered different CustomerIDHow can i do it ?Thanks in advance |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
Sheila Leverson
Starting Member
2 Posts |
Posted - 2010-05-10 : 18:57:33
|
I don't believe you can do that "automatically". It will require some work on your part to come up with the correctly incremented address_id. Most commonly this is done in a stored procedure that handles insertion into the table.quote: Originally posted by Dufresne Hi , I'm newbie for SQL.I'm stuck with a problemI've following tableAddress ( AddressID TINYINT NOT NULL, CustomerID INT NOT NULL, Address VARCHAR(200) NOT NULL) AddressID and CustomerID are composite Primary Key.CustomerID is Foreign Key to Customer Table.What i want is automatic increment AddressID with same CustomerIDSuppose that , we'll add 3 addreses for customer whose id is 1 and 4 addresses for the customer whose id is 2.So my table shall look likeAddressID CustomerID Address1 1 'Address'2 1 'blabla'3 1 '...'1 2 '..'2 2 '....'3 2 '.....'4 2 '....'AddressId shall increment and automatically become 1 when it's entered different CustomerIDHow can i do it ?Thanks in advance
|
|
|
|
|
|