| Author |
Topic |
|
lsy
Yak Posting Veteran
57 Posts |
Posted - 2006-04-12 : 04:55:39
|
| how to insert a value to a autonumber column? |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2006-04-12 : 05:00:43
|
Look up "SET IDENTITY_INSERT" in BOL.Here is a sample from BOL:This example creates a table with an identity column and shows how the SET IDENTITY_INSERT setting can be used to fill a gap in the identity values caused by a DELETE statement.-- Create products table.CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))GO-- Inserting values into products table.INSERT INTO products (product) VALUES ('screwdriver')INSERT INTO products (product) VALUES ('hammer')INSERT INTO products (product) VALUES ('saw')INSERT INTO products (product) VALUES ('shovel')GO-- Create a gap in the identity values.DELETE products WHERE product = 'saw'GOSELECT * FROM productsGO-- Attempt to insert an explicit ID value of 3;-- should return a warning.INSERT INTO products (id, product) VALUES(3, 'garden shovel')GO-- SET IDENTITY_INSERT to ON.SET IDENTITY_INSERT products ONGO-- Attempt to insert an explicit ID value of 3INSERT INTO products (id, product) VALUES(3, 'garden shovel').GOSELECT * FROM productsGO-- Drop products table.DROP TABLE productsGO |
 |
|
|
a_r_satish
Yak Posting Veteran
84 Posts |
Posted - 2006-04-12 : 06:06:49
|
| try this..set identity_insert <tablename> oninsert into <tablename> values(<colname>...)set identity_insert <tablename> offsatish.r"Way to success is always under Construction" |
 |
|
|
lsy
Yak Posting Veteran
57 Posts |
Posted - 2006-04-12 : 06:08:09
|
| i got 2 primary key in the database, one is the autonumber column another is the ID column... but it seem the data in the primary key column can duplicate.... |
 |
|
|
a_r_satish
Yak Posting Veteran
84 Posts |
Posted - 2006-04-12 : 07:31:51
|
| Confusing...Sample records please...satish.r"Way to success is always under Construction" |
 |
|
|
lsy
Yak Posting Veteran
57 Posts |
Posted - 2006-04-12 : 20:22:10
|
| example i got 3 columns... index, ID, col_X... at first i set my index to autonumber and the ID to primary key... my record data as followindex ID col_x3 A123 xx4 B234 xxx1 C345 xx2 D456 xxxmy ID column is arrange ascending but my index column is not, suppose last record enter will place at the bottom but is seem index-4 is place on the second row.this is my desire record placementindex ID col_x1 C345 xx2 D456 xxx3 A123 xx4 B234 xxxhow my sql insert statement should look like... or did i set anything wrong in my database?? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-04-12 : 21:21:13
|
records are not stored in the database in any particular order. You don't have to worry about how SQL Server store your records. The important thing is when you retrieve the records, how do you want it to order ?You should use ORDER BY to define the sequence how the records are retrieved back.example :select * from yourtableorder by index KH |
 |
|
|
lsy
Yak Posting Veteran
57 Posts |
Posted - 2006-04-12 : 23:05:05
|
| i'm using access as my database and use vb to control so in the dtaabase i saw the particular oder appear... |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-04-13 : 00:59:50
|
| If you are displaying the data on the grid or taking them in the recordset, just while retreving the data use order by clause what Khtan gave you .. It should work fine ..If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
lsy
Yak Posting Veteran
57 Posts |
Posted - 2006-04-13 : 02:08:20
|
| i know that work but i want when open database manually it look more organise... |
 |
|
|
|