Forum Moderators: open

Message Too Old, No Replies

mysql vs sql

         

Pico_Train

3:38 pm on May 5, 2009 (gmt 0)

10+ Year Member



I usually work with mysql but a new client is using sql server.

My question has to do with inserts, more specifically when inserting a new row in a table.

So in MySql I can do:

INSERT into table VALUES(DEFAULT,"'.$post['variable'].'")

Notice the DEFAULT for the new id created for a new row in the table.

How do I do that in SQL? I have tried a few things and nothing has worked. Is there an equivalent to DEFAULT for a new row id in SQL?

Thanks!

LifeinAsia

4:02 pm on May 5, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If you don't supply a value, SQL uses the default value set in the table definition.

Demaestro

4:36 pm on May 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, just make sure that you list the values you are passing in, you can only skip that step if you are passing in a value for each column.

So you will want something like this.

INSERT into table (column_name) VALUES("'.$post['variable'].'")

Pico_Train

4:41 pm on May 5, 2009 (gmt 0)

10+ Year Member



OK cool, thanks for the info.

If I look in the frontend of the db for that table, the id column is blank under the DEFAULT value.

What should I do there?

Demaestro

5:39 pm on May 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



assign a default value to that field.

If you want it to generate an id for you, then you may have to create a sequence or something else to use for that id.