Question subject: Create auto numbered column in mysql query
Posted: Mon Apr 26, 2010 7:38 am
Joined: Mon Apr 26, 2010 7:31 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
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;
msi_333
Question subject: Re: Create auto numbered column in mysql query
Posted: Mon Apr 26, 2010 9:33 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
thanks for sharing , I never tried such query before .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
orangewine6
Question subject: Re: Create auto numbered column in mysql query
Posted: Sun May 02, 2010 10:19 am
Joined: Sun May 02, 2010 10:07 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
sameeraa4ever wrote:
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;
Thanks for sharing of that that's very helpful!
make money from home
krishcode
Question subject: Re: Create auto numbered column in mysql query
Posted: Tue May 04, 2010 5:50 am
Joined: Tue May 04, 2010 5:44 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
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".