sql - Create custom defined unique identifier -
i have table uniqueidentifier column. insert script looks :
insert [users] ([userid], [name], [surname]) values (newid(), 'somename', 'somesurname')
newid() creates new guid, inserted table. create data defined id column, not automatically generated. e.g. 'a0000000-0000-0000-0000-000000000000'. code doesn't work because throws error 'string or binary data truncated.' :
insert [users] ([userid], [name], [surname]) values ('a0000000-0000-0000-0000-000000000000', 'somename', 'somesurname')
i tried cast custom guid, not successful well.
insert [users] ([userid], [name], [surname]) values (cast('a0000000-0000-0000-0000-000000000000' uniqueidentifier), 'somename', 'somesurname')
do have clue how can solve inserting data custom defined id?
you don't have cast it. sql server you.
this code works well:
create table x ( uniqueidentifier ); insert x values ('a0000000-0000-0000-0000-000000000000') ; insert x values ('bbe46a77-3518-40e4-9b77-3275f3531b8b') ; select * x ;
Comments
Post a Comment