how to generate ID field with auto numbering
-
Example:
Create table myTable(studentID int,
firstName nvarchar(25),
lastName nvharchar(23)
)I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).
-
Example:
Create table myTable(studentID int,
firstName nvarchar(25),
lastName nvharchar(23)
)I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).
Hi, this is the SQL statement PHPMyAdmin comes up with when creating a table with two fields, one of them auto-incrementing:
CREATE TABLE `db1`.`test3` (
`name` VARCHAR( 12 ) NOT NULL ,
`ID` INT NOT NULL AUTO_INCREMENT ,
PRIMARY KEY ( `ID` )
) ENGINE = MYISAMHope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Example:
Create table myTable(studentID int,
firstName nvarchar(25),
lastName nvharchar(23)
)I want the studentID field to be auto generated automatically, like 1,2,3 or 0,1,2 etc each time i insert a record. How do I do that inside a query (not in design mode).
If you mean in SQLServer you must use IDENTITY IDENTITY is the auto generate mode of an number field
Human knowledge belongs to the world http://www.rad.pasfu.com/index.php