Sometimes we need concatenate the primary key with some other format, you can simply implement that using this snippet. The output will be like this if Primary Auto-Increment value is '1', then the out put will be FORMATSTRINGCOMESHERE001.
CREATE TABLE DEMOTABLE(DEMOIDCOLUMN INT IDENTITY PRIMARY KEY, DEMOCONCATIDCOLUMN AS 'FORMATSTRINGCOMESHERE'+RIGHT(1000+DEMOIDCOLUMN,3));-- YOU CAN SPECIFY THE FORMAT,LENGTH AND ALL IN THIS LINE
INSERT DEMOTABLE DEFAULT VALUES;
INSERT DEMOTABLE DEFAULT VALUES;
INSERT DEMOTABLE DEFAULT VALUES;
SELECT * FROM DEMOTABLE; DROP TABLE DEMOTABLE
|
No responses found. Be the first to respond and make money from revenue sharing program.
|