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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inserts

Author  Topic 

shelbyoh
Starting Member

14 Posts

Posted - 2010-02-18 : 15:27:42
I am new to work with databases.

I have database tables they are Clients, Projects and Tbpacks.
Clients columns are Client_ID [int] Primary Key Autoincrement, ClientName.

Projects columns Project_ID [int] Primary Key Auto
ProjectName, and ProjectNumber
with FK Client_ID FK tbpacks_ID

Tbpacks columns tbpacks_ID [int] Primary Key Auto
tbpacksName, tbpacksNumber, Division
on the webpage I have the follow input text boxes

Client Name:
Project Name:
Project Number:
tbpacks Name:
tbpacks Number:
Division:
My insert code looks like this.

insert Client.ClientName, ProjectProjectName,ProjectNumber,Tbpacks.tbpacksName,Tbpacks.tbpacksNumber,Tbpacks.Division
INTO Projects, Clients, BidPackage
Where Project.Client_ID = Client.Client_ID AND
Project.Tbpacks_ID = Tbpacks_ID AND
Client.Client_ID = Tbpacks_ID And
Tbpacks_Project_ID = Project.Project_ID


When I hit the save or save and New Entry

X002548
Not Just a Number

15586 Posts

Posted - 2010-02-18 : 15:32:29
Is there a question?

Is this Access?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

shelbyoh
Starting Member

14 Posts

Posted - 2010-02-18 : 15:44:06
This is Sql server question.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-02-18 : 15:47:02
ok...and you asking if the insert is good?

No

Tell us what you are trying to do?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

shelbyoh
Starting Member

14 Posts

Posted - 2010-02-18 : 16:56:37
when a person fill out the form which has the following text boxes

Client Name:
Project Name:
Project Number:
tbpacks Name:
tbpacks Number:
Division:

and click on save they data need to insert into the follow column in the database and also when a person go to query the database for a client or project number it list all the people relate to the project number I can do query with joins. I put test data manually and the query works. I have problem creating the proper relationship so when they enter data via the form. I need for it to insert across the tables or should I make all one table. I still would have problems with relationship because I have other table that has to reference the tables.help please.

 
1)insert Clients values( ClientNameTxtBox )
--a trigger for this table after insert to get @@identity (which is client_id);store it in local a variable @identity1

2) insert into Tbpacks values ( Name TxtBox , Number TxtBox, Division TxtBox )
--a trigger for this table after insert to get @@identity (which is tbpacks_ID ) ; store it in local a variable @identity2

3) insert into Projects( Client_ID, tbpacks_ID, ProjectName, ProjectNumber)
values ( @identity1 , @identity2, ProjectNameTxtBox, ProjectNumberTxtBox )


But I don't know enough about Databases to do so.

Go to Top of Page

shelbyoh
Starting Member

14 Posts

Posted - 2010-02-18 : 16:57:19
I don't know how to set triggers.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-02-18 : 23:24:53
Do you know what books online (BOL) is?

You need to look up SCOPE_IDENTIY

Or Google it



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-19 : 00:13:13
quote:
Originally posted by shelbyoh

when a person fill out the form which has the following text boxes

Client Name:
Project Name:
Project Number:
tbpacks Name:
tbpacks Number:
Division:

and click on save they data need to insert into the follow column in the database and also when a person go to query the database for a client or project number it list all the people relate to the project number I can do query with joins. I put test data manually and the query works. I have problem creating the proper relationship so when they enter data via the form. I need for it to insert across the tables or should I make all one table. I still would have problems with relationship because I have other table that has to reference the tables.help please.

 
1)insert Clients values( ClientNameTxtBox )
--a trigger for this table after insert to get @@identity (which is client_id);store it in local a variable @identity1

2) insert into Tbpacks values ( Name TxtBox , Number TxtBox, Division TxtBox )
--a trigger for this table after insert to get @@identity (which is tbpacks_ID ) ; store it in local a variable @identity2

3) insert into Projects( Client_ID, tbpacks_ID, ProjectName, ProjectNumber)
values ( @identity1 , @identity2, ProjectNameTxtBox, ProjectNumberTxtBox )


But I don't know enough about Databases to do so.




i think what you need is something like

DECLARE @Client_ID int,@tbpacks_ID int

insert Clients values( @ClientNameTxtBox )
SELECT @Client_ID=SCOPE_IDENTITY()

insert into Tbpacks values ( @NameTxtBox , @NumberTxtBox, @DivisionTxtBox )
SELECT @tbpacks_ID=SCOPE_IDENTITY()

insert into Projects( Client_ID, tbpacks_ID, ProjectName, ProjectNumber)
values ( @Client_ID , @tbpacks_ID, @ProjectNameTxtBox, @ProjectNumberTxtBox )

...

@ProjectNameTxtBox etc are parameters passsed from your form with values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-19 : 00:14:10
see this also

http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -