Reputation: 10983
Is there a way to insert a row in SQL CE using the INSERT Statement when I have a GUID field.
In C#, I use
ID = Guid.NewGuid()
But in SQL console I can't find a keyword to do this.
I've found just this one :
> Insert into Customer (ID, Name) values ('f5c7181e-e117-4a98-bc06-733638a3a264','MyCustomer')
What about if I have a lot of rows to insert ?
Upvotes: 2
Views: 6152
Reputation: 914
In C#, GUID are lower case so use LOWER(NEWID())
in SQL if you want them to look similar.
Upvotes: 0
Reputation: 815
To have a GUID
on a field you can set the default of a column to be NEWSEQUENTIALID()
. So, for example:
CREATE TABLE tableName (
Guid UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID(),
Name VARCHAR(100)
);
Then insert into the table by executing the following query:
INSERT INTO tableName (Name) VALUES ('Test');
I'm not sure if NEWSEQUENTIALID()
is supported in CE or not, as I've never used CE for development.
Upvotes: 1