PHP mySQL – Insert new record into table with auto-increment on primary key

Use the DEFAULT keyword: $query = “INSERT INTO myTable VALUES (DEFAULT,’Fname’, ‘Lname’, ‘Website’)”; Also, you can specify the columns, (which is better practice): $query = “INSERT INTO myTable (fname, lname, website) VALUES (‘fname’, ‘lname’, ‘website’)”; Reference: http://dev.mysql.com/doc/refman/5.6/en/data-type-defaults.html

MSSQL Select statement with incremental integer column… not from a table

For SQL 2005 and up SELECT ROW_NUMBER() OVER( ORDER BY SomeColumn ) AS ‘rownumber’,* FROM YourTable for 2000 you need to do something like this SELECT IDENTITY(INT, 1,1) AS Rank ,VALUE INTO #Ranks FROM YourTable WHERE 1=0 INSERT INTO #Ranks SELECT SomeColumn FROM YourTable ORDER BY SomeColumn SELECT * FROM #Ranks Order By Ranks see … Read more

currval has not yet been defined this session, how to get multi-session sequences?

The currval will return the last value generated for the sequence within the current session. So if another session generates a new value for the sequence you still can retrieve the last value generated by YOUR session, avoiding errors. But, to get the last generated value on any sessions, you can use the above: SELECT … Read more

MySQL: bigint Vs int

The difference is purely in the maximum value which can be stored (18,446,744,073,709,551,615 for the bigint(20) and 4,294,967,295 for the int(10), I believe), as per the details on the MySQL Numeric Types manual page. Incidentally, the use of (20) and (10) is largely irrelevant unless you’re using ZEROFILL. (i.e.: It doesn’t actually change the size … Read more

How do I add a auto_increment primary key in SQL Server database?

It can be done in a single command. You need to set the IDENTITY property for “auto number”: ALTER TABLE MyTable ADD mytableID int NOT NULL IDENTITY (1,1) PRIMARY KEY More precisely, to set a named table level constraint: ALTER TABLE MyTable ADD MytableID int NOT NULL IDENTITY (1,1), CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (MyTableID) … Read more

tech