Switch to full style
Tutorials, source code, tips and tricks related to mysql
Post a reply

Create auto numbered column in mysql query

Mon Apr 26, 2010 7:38 am

Create auto numbered column in mysql query

select @rownum:=@rownum+1 nowef,
p.* from item p, (SELECT @rownum:=0) r
order by item_code
desc limit 10;
:wink: :wink:



Re: Create auto numbered column in mysql query

Mon Apr 26, 2010 9:33 am

thanks for sharing , I never tried such query before .

Re: Create auto numbered column in mysql query

Tue May 04, 2010 5:50 am

Syntax for SQL Server

The following SQL statement defines the "P_Id" column to be an auto-increment primary key field in the "Persons" table:
CREATE TABLE Persons
(
P_Id int PRIMARY KEY IDENTITY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature.

By default, the starting value for IDENTITY is 1, and it will increment by 1 for each new record.

To specify that the "P_Id" column should start at value 10 and increment by 5, change the identity to IDENTITY(10,5).

To insert a new record into the "Persons" table, we will not have to specify a value for the "P_Id" column (a unique value will be added automatically):
INSERT INTO Persons (FirstName,LastName)
VALUES ('Lars','Monsen')

The SQL statement above would insert a new record into the "Persons" table. The "P_Id" column would be assigned a unique value. The "FirstName" column would be set to "Lars" and the "LastName" column would be set to "Monsen".

Post a reply
  Related Posts  to : Create auto numbered column in mysql query
 create named query     -  
 create a named query within entity class     -  
 Auto image size     -  
 column can't be null     -  
 Get column alias in php     -  
 Get table column flag in php     -  
 Join Column by Primary Key     -  
 EJB-QL IN where query     -  
 update query example     -  
 Run query and search from ASP     -