Hello the following is schema of the table in question
employee (emp_no,emp_fname,emp_lname,birth_date,residence)
The emp_no is INT and is a primary key. Currently there are random big numbers in the column as IDs and I need to reset the column and make it so that it adds the autoincremented ID to the existing entries plus to every new entry I will add.
Related
I have been developing one application to register the student's details for admission. In SQL Server, I have to save the records and generate one reference number. That registration should be unique.
At the present, I am taking max number from the table and insert into the table. Duplicate records inserted in milliseconds. How to avoid duplicate records in the reference number column? In my application, 1000 concurrent users register at the same time.
Ex. IRCTC Ticket booking. They are generating PNR without duplicate.
There is no reason why a regular auto increment primary key column should not suffice here:
CREATE TABLE students (
id INT NOT NULL IDENTITY PRIMARY KEY,
...
)
SQL Server would never generate a duplicate value for the above id column. If, for some reason, this would not meet your expectations, then you could consider using a UUID for each student record, using the NEWID() function.
I am designing a database with multiple tables like users, content, etc. I want to allot id to each row in the tables.
So what are the criteria to generate an unique id for each row in each table. And should I make the id in auto increment mode?
I have a simple user table in database with following columns:
Id int primarykey Identity column
UserName nvarchar
Points int
There is another table Posts in database which have many to one relationship with User Table means a user can have multiple post. The columns of Posts table are:
PostId int primaryKey Identity column
Message nvarchar
Post_Id foreign key
Now, suppose any user logged in and post something than in database, PostID is auto created and auto incremented and his message is got posted. UserId column is same as id column in user table.
There is third table called Comment table which have many to one relationship with user table.The columns in this table are
CommentId int primaryKey Identity column
Message nvarchar
Comment_Id foreign key
Now, I want to write a trigger which increases points value by 10 in user table if there is an increase in no of post in post table and decrease its value by 10 if there is decrement in post table.
Similar is the situation for comment table too, i.e for every increment in comment, point increment to +5 and with every decrement in comment, -5.
I have seen multiple examples on stack overflow but not got any idea. Moreover, not seen any example to update column value with trigger. Please suggest me how to accomplish this.
I am trying to make generalized master search for my MS-SQL data. Let me explain what I had done till now:
Firstly, I fill one combo box with all the table names.
Then, fill second combo box with columns of selected table from first combo box.
I run general database query like select * from combobox1.text where combobox2.text='someValue'. Everything works fine for me, but I am not able to get foreign key data which is primary in another table.
What i need
suppose Table A has columns: 1 primary key, 2 name of id. And Table 2 with: 1 as primary key column, 2 as address column, and 3 as foreign key column. When I run select * from table2
I get result of foreign key in terms of id, I want value of table1.2 column value.
Why i am asking
This because with this type of system, I can query each and every row in database without manual coding for each table.
Images to explain better
Employee Master Table
Attendance Table
Result i want
In my table I want to have an ID column that is going to be unique and it is going to be autoincremented. I want to start from 0.
How can I implement it?
Basically, create a column of type INTEGER PRIMARY KEY or a column called ROWID, then don't specify the value when inserting a row.
Full details are on the SQLite page on Autoincrement.