Editor: New uniqueidentifier when inserting row in sql server database

Editor: New uniqueidentifier when inserting row in sql server database

adrianriepl4adrianriepl4 Posts: 11Questions: 4Answers: 0

Hello guys

I have a question. I can't find anything in the docs about inserting a new uniqueidentifier into a new row.
When I tried to insert a row in my table, this error appeared:

"SQLSTATE[23000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert the value NULL into column 'GUID', table 'TestEditor.dbo.TestUser'; column does not allow nulls. INSERT fails."

Since I have my primary key set to NOT NULL this error message is obvious but why isn't there a new uniqueidentifier generated?

How can I accomplish that, when I insert a new row, there will be a new uniqueidentifier generated (like NEWID() in Transact-SQL ) as a primary key in the table?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Generally speaking, Editor assumes that the database table is set up to insert the id from a sequence automatically, as that is the most efficient and effective way of doing it. You could read the current max() or get a uuid, but you are risking a conflict if another record is inserted at the same time.

    I would suggest creating an identity column in SQL Server for the primary key.

    Allan

  • adrianriepl4adrianriepl4 Posts: 11Questions: 4Answers: 0

    Is it not possible to create like a custom insert function? Where you just get the data and the can build your 'own' SQL statement?

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Answer ✓

    Certainly - the data that is submitted is submitted in the format described in the manual here: https://editor.datatables.net/manual/server . With that you can construct the SQL as you need.

    Allan

  • adrianriepl4adrianriepl4 Posts: 11Questions: 4Answers: 0

    Am I right that I have to build this with the REST interface?
    http://editor.datatables.net/examples/advanced/REST.html

    Thanks already you helped me a lot!

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Answer ✓

    If you don't want to use the PHP libraries provided, or they don't cover your use case, then yes, you'd need to write some code on the server-side.

    Allan

  • adrianriepl4adrianriepl4 Posts: 11Questions: 4Answers: 0

    Thanks for your help! You opened my eyes and I know now how to do it!
    Thank you so much!

This discussion has been closed.