Showing posts with label alter. Show all posts
Showing posts with label alter. Show all posts

Monday, March 26, 2012

help for creating stored procedure

ALTER PROCEDURE companyinsert

@.companyid INT IDENTITY(1,1) NOT NULL,
@.companyname varchar(20),
@.address1 varchar(30)

AS

INSERT INTO companymaster
( companyname, address1)
VALUES (@.companyname,@.address1)

i don't want the companyname having the same names are recorded again with the different company id..

Can anyone help me and modify my code according it's giving error...in the @.companyid.

It is being done in sql server 2005 with asp.net C# 2005

You cannot declare a parameter with IDENTITY property in a stored proc. I think what you are looking for is more along these lines. You might want to read up documentation on SCOPE_IDENTITY(). Briefly, it returns the Identity value that was created due to your INSERT.

ALTER PROCEDURE companyinsert@.companyidINT OUTPUT,@.companynamevarchar(20),@.address1varchar(30)ASBEGINSET NOCOUNT ONIFNOT EXISTS(SELECT *FROM companymasterWHERE CompanyName = @.companynameAND Address1 = address1)BEGININSERT INTO companymaster ( companyname, address1)VALUES (@.companyname,@.address1)SELECT @.companyid = SCOPE_IDENTITY()ENDSET NOCOUNT OFFEND

Sunday, February 19, 2012

help

hi i need some help.I tried using alter table tablename <modify columnname datatype> to change the primary key of the table but it didnt work.I was prompted that there is an error because of using the term modify.what is the command that i should use?

Quote:

Originally Posted by izzo

hi i need some help.I tried using alter table tablename <modify columnname datatype> to change the primary key of the table but it didnt work.I was prompted that there is an error because of using the term modify.what is the command that i should use?


Hi
I don't think you can modify the primary key. You need to delete it and then create a new one on a different column|||first drop the primary key constraint
alter table tablename drop pk_constraint
then add a new constraint to whatever column you want to add it on to, making sure that the values in the column obliges the rules of primary key.
alter table tablename add constraint pk_col1 primary key(col1)

hope this one helps u