Showing posts with label auto. Show all posts
Showing posts with label auto. Show all posts

Monday, March 19, 2012

How to set up auto incrementing for a field

I have a database table. I need to set a particular data field to allow for Auto Incrementing. Basically I need to set up the initial integer value to start at. Then to specify the amount to increment by.

What I have done so far is to right click on the field name in SQL Server 2005. Then, on the pop-up menu I select the menu option for properties.

When the properties are displayed I see some fields listed in dark grey but I am not able to edit these fields. In other words, if I try to type text in this field, nothing happens. The fields I am talking about are:

Identity Increment

Identity Seed

Is Identity

Does anyone know what the problem is? What do I have to do to edit these fields.

Check if you have the necessary permissions.|||You can not change the properties directly in the Column Properties window, instead, you can right click the column and choose 'Modify'. Enjoy itSmile

how to set up a 'cascading delte' in mssql

I'm used to working with Access but have moved to MSSQL 2005.
I have these tables:
tblCustomer: customerID (auto), name (nvarchar,50)
tblOrders: orderID (auto), customerID (int)
I use SSMSE. How can I set it up so that the related records in tblOrders
are deleted if I delete a customer.
Thanks.
Jesper
Jesper F (askfortheemail@.ask.com) writes:
> I'm used to working with Access but have moved to MSSQL 2005.
> I have these tables:
> tblCustomer: customerID (auto), name (nvarchar,50)
> tblOrders: orderID (auto), customerID (int)
> I use SSMSE. How can I set it up so that the related records in tblOrders
> are deleted if I delete a customer.
ALTER TABLE tblOrders ADD
CONSTRAINT fk_order_customers FOREIGN KEY (customerID)
REFERENCES tblCustomers (customerID) ON CASCADE DELETE
Although, I must say that from my corners, this looks like a funny
business rule...
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
|||> ALTER TABLE tblOrders ADD
> CONSTRAINT fk_order_customers FOREIGN KEY (customerID)
> REFERENCES tblCustomers (customerID) ON CASCADE DELETE
> Although, I must say that from my corners, this looks like a funny
> business rule...
Those were imaginary tables, but thanks for pointing me in the right
direction.
Jesper