1
Answer

How can the GUID (uniqueidentifier) be generated directly in SQL?

haji

haji

12y
894
1
Hi 
I am inserting values in a table directly without writing the query for create table.
The columns I am using are Id(uniqueidentifier,primarykey),Name(varchar).Now I can insert the Name values directly but how can the GUID can automatically generated when I move from one row to other row?Because when I dont insert anything thinking it would be generated and moving on to next row it is giving error :Column values cannot be null.How to fix it?
 
Thanks,..
Answers (1)
1
Sukesh Marla

Sukesh Marla

NA 11.8k 1.2m 12y
Put Default Value for Column as NewId()


NewId() function gernerates and returns UniqueIdentifier value

Or Even in Insert query call this functiion to explictly insert the value,.


Check this is correct answeer if it helped.
Accepted