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.
| Author |
Topic |
|
vuimotti87
Starting Member
1 Post |
Posted - 2010-05-21 : 11:18:02
|
| Hi All !Often when creating a table for its own primary key to growth but that it is the type of case studies. Now if the key types of characters you want it up, how?Example:CREATE TABLE Student(StudCode varchar (5),Birth date)I want each key increases with sample A0001, A0002 ... They must do.Who can help me many thanks! |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-05-21 : 12:03:35
|
| Have a look at the below link. It may of some help to you.http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server |
 |
|
|
lazerath
Constraint Violating Yak Guru
343 Posts |
Posted - 2010-05-21 : 12:14:25
|
| IF OBJECT_ID('tempdb..#tbl1') IS NOT NULL DROP TABLE #tbl1;CREATE table #tbl1 (TCODE AS CHAR(65 + ID / 10000) + RIGHT('0000' + CONVERT(VARCHAR(5),ID),4) PERSISTED NOT NULL PRIMARY KEY,ID INT IDENTITY(0,1) NOT NULL,Field1 INT,Field2 varchar(10));GOINSERT INTO #tbl1 (Field1,Field2) SELECT 1,'AAA'GO 30001 select * FROM #tbl1 order by IDDROP TABLE #tbl1;/*Results:TCODE ID Field1 Field2A0000 0 1 AAAA0001 1 1 AAAA0002 2 1 AAAA0003 3 1 AAAA0004 4 1 AAAA0005 5 1 AAAA0006 6 1 AAAA0007 7 1 AAAA0008 8 1 AAAA0009 9 1 AAA...A9996 9996 1 AAAA9997 9997 1 AAAA9998 9998 1 AAAA9999 9999 1 AAAB0000 10000 1 AAAB0001 10001 1 AAAB0002 10002 1 AAAB0003 10003 1 AAA...B9997 19997 1 AAAB9998 19998 1 AAAB9999 19999 1 AAAC0000 20000 1 AAAC0001 20001 1 AAAC0002 20002 1 AAA...C9997 29997 1 AAAC9998 29998 1 AAAC9999 29999 1 AAAD0000 30000 1 AAA*/ |
 |
|
|
|
|
|