Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ssassassa9
Starting Member
3 Posts |
Posted - 2012-08-09 : 11:44:19
|
| I'm currently doing a school charity project. On the website, students can register for the event, and the registration details goes into a database. I couldn't find a code which is able to assign numbers to registered people in ascending order. Help would greatly be appreciated. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-08-09 : 11:48:44
|
| CREATE TABLE Students(StudentID int NOT NULL IDENTITY(1,1), StudentName varchar(50) NOT NULL)INSERT Students(StudentName) VALUES('Fred Flintstone')INSERT Students(StudentName) VALUES('Barney Rubble')SELECT * FROM Students |
 |
|
|
ssassassa9
Starting Member
3 Posts |
Posted - 2012-08-09 : 12:38:02
|
| Sorry, but this is actually my first time doing these stuff, could you please explain the query above? |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-08-09 : 12:45:49
|
| SQL Server has a feature known as identity. It's a way to create automatically incrementing numbers. The StudentID column is set to start at 1 and increase by 1 value. The first value I inserted (Fred Flintstone) will get StudentID=1. The 2nd value (Barney Rubble) will get StudentID=2. Each new name you insert will increment the StudentID column by 1. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
ssassassa9
Starting Member
3 Posts |
Posted - 2012-08-09 : 12:52:58
|
| Thanks folks, appreciate your help :)EDIT: "Syntax error near 'IDENTITY(1,1), StudentName varchar(50) NOT NULL) INSERT Students(StudentName) V' at line 1" This is what I got. I guess the free sql database on freemysql.net has no identity function. |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-08-09 : 13:12:20
|
| SQLTeam is a Microsoft SQL Server website. There's a MySQL forum over at http://dbforums.com/. You'd use the AUTO_INCREMENT property in MySQL to accomplish the same thing. |
 |
|
|
|
|
|