July 2, 2006 at 1:12 am
how can we insert value of one attribute in the database automatically??i.e. it should be automatically generate. i'm using sql server 2000.
July 2, 2006 at 4:14 am
Care to elaborate a bit?
Is this about using the identity datatype or using a default value?
July 2, 2006 at 9:46 pm
Agreed... a little more info would help... should it be a date, and sequential ID, what???
--Jeff Moden
Change is inevitable... Change for the better is not.
July 3, 2006 at 5:01 am
Automatical generated values are in common defaults which a bound to a column. An example for a special default is the identity column which increments itself for each insert made. If you want to have another / a custom incrementation you will have to code that on your own in a function. The function can be itself bound to a default constraint and this to a table.
HTH, Jens Suessmeyer.
---
---
July 3, 2006 at 2:49 pm
yes; it's a sequential id
July 3, 2006 at 3:39 pm
Great... and simple, too...
When you create a table, create your "sequential ID" column with the IDENTITY property...
For example... this will create a table, insert 3 rows, insert 3 more rows, then list all the rows by the sequential ID and then list all the rows by the other column... notice how the RowID column works... you can find out a lot more looking up CREATE TABLE and IDENTITY in Books Online...
CREATE TABLE JustaTest
(
RowNum INTEGER IDENTITY(1,1) PRIMARY KEY CLUSTERED,
SomeOtherCol VARCHAR(10)
)
INSERT INTO JustaTest
(SomeOtherCol)
SELECT 'Sam' UNION ALL
SELECT 'Dean' UNION ALL
SELECT 'Sally'
INSERT INTO JustaTest
(SomeOtherCol)
SELECT 'Joe' UNION ALL
SELECT 'Andy' UNION ALL
SELECT 'Adelle'
SELECT *
FROM JustaTest
ORDER BY RowNum
SELECT *
FROM JustaTest
ORDER BY SomeOtherCol
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply