Skip to content
Advertisement

How can I make this code work on SQL Server

I was wondering why my SQL code isn’t working properly on SQL Server while when I upload it on phpmyadmin it works perfectly. Is it some difference between those SQL’s? Is someone able to make this code working well on SQL Server? I’ve posted only part of database but with your help I’ll get done the rest.

Advertisement

Answer

As a starter, your original MySQL code has issues:

  • inserting an empty string in an auto-incremented column is not supported; instead, you should not insert in that column, and let the database automatically assign a value to it (this requires explicitly listing the columns that you want to insert into, which is a best practice in SQL anyway)

  • you need to insert in table Klasa first, then insert into referencing table Czytelnicy

When it comes to translating this to SQL Server:

  • auto_increment is not supported; you can use identity(1, 1) instead

  • the int does not accept a length

This would work:

Demo on DB Fiddle

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement