Authorisation System Database Design [closed] - sql-server

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am working on an Authorization system for a CMS. I have following table structure:
All the other tables are ok for me but i want to know about the best practice
for a GroupPermission table as described below.
Users:
UserId,Name
Groups:
GroupId,Name
GroupUser:
GroupUserId,GroupId,UserId
Modules:
ModuleId,Name
Permissions:
PermissionId,Name,ModuleId,isAllowed
Approach 1:
GroupPermission:
GPId GroupId ModuleId Permissions(var char)
1 1 1 View:true,Create:false,Delete:true,Edit:false
2 1 2 View:ture,inviceCreate:false,AssignCreate:false
Approach 2:
GroupPermission:
GPId GroupId PermissionId
1 1 1
2 1 2
3 1 3
I need your suggestion over the two approaches mentioned ,in first approach there is an advantage of only one row returned for a specific Group but i am concatenating Permissions in a string , so there would be an overhead of string parsing method,
In second approach i am using 'Id' instead of string.
since this table is the mostly used table and would effect the overall performance of application , so this table needs to be optimized to the maximum.
I have studied the databases of other Cms like word press,orchard,silver stripe etc but they only have few user and Groups tables and couldn't find anything useful for my requirement.
Any other alternate suggestions or ideas are greatly appreciated.

Go with the second, normalized approach.
Keeping delimited data in a single column is wrong in 99.999% of the cases.
Having only a single row for each group permision is not an advantage, considering the string manipulation overhead for otherwise is le selects, inserts, updates and deletes.
Just take a moment to think what if someone wants to remove a permision from a group: you will have to figure out if the group even have this permoision, and then find out where it's text starts and where it ends, cut it out of the full string, and only then update the record.
While with the normalized version all you have to do is write a simple delete statement...

Related

Performance implications to keep count of how many times user chose certain entity [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
We have a feature request where a said users choice of certain entity has to be recorded, this would be an integer that is incremented every time the user chooses that specific entity. This information is later used for ordering the said entities every time the user gets all its associated of the said entities.
Assuming that we are limited to sql server as our persistent storage and that we could have !millions of users and each user could have anywhere between 1 to 10 of those said entities, performance would quickly become an issue.
One option is to have an append only log table where the user id and entity id are saved every time a user chooses an entity and on the query side we get all the records and group by entity id. This could quickly cause the table to grow very large.
The other would be to have three columns consisting of user id, entity id and count and we would increment the count every time the user chooses the said entity.
The above two options are what I have been able to come up with.
I would like to know if there are any other options and also what would be the performance implications of the above solutions.
Thanks
If this was 2001 performance could be an issue.
If you are using SQL server 2012 or 2016
then I say either are good.
Ints or Big ints index well and the performance hit would be insignificant.
You could also store the data in a xml or json varchar field
but I would go with your first option.
Using Big Ints and make sure you use indexes no matter what you do

How to generate unique ids in C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am developing an app which requires to generate an id for new users I want to do it with the smallest number of characters that allows me to create 100 billion diferent possible ids so how should I do that and how to avoid giving two users the same it? Should I look if that id exists? Should I use a random id generator or give ids in order like 001 002 and so on?
This depends entirely on what kind of functionality you expect from this id, do you intend for these id's to correlate with persisted data, such as a database? If this is the case, it might be more prudent to let the database handle the unique ID generation for you. Otherwise, using sequential values such as 1,2,3... etc would probably be ideal. unsigned long will keep you covered for the first 2 billion users... If you somehow go beyond that, you can rethink your data storage then.
The question is very broad.

How to generate a database table from a .csv file automatically? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a CSV file with 110 columns.
Preparing a table with 110 columns manually will take me forever. Is there any other way to do it?
I tried to create a table , but I was wondering if there is any way that when I create a table in putty session, it takes the column names and number of columns by itself.
Before you jump the gun and just make one huge table, you should sit down and think about if having one massive table really is useful in the long run. Normalization can be a wonderful thing, and depending on the size of your input it would be much less of a hassle to structure everything now rather then later.
As far as deciding what to import, toss it into excel or mysql and drop the fields you don't want/need. Mysql will actually build the structure of your table from the csv file, as long as you give it the right delimiter (comma, semicolon, whatever seperates your fields).

How to update data in database without using several queries? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In my application, it shows student's subject and it's result. First, I have written this application to show the subject and results only. But, now we need to extend it's functionality to update subjects results from admin panel.
Problem is in my database, I have recorded results, if the student has taken-part in the given subject. As an example if a student is absent for mathematics, in the application subject will be printed without results for mathematics.
What I need is to update the results for each student. What I have noticed was, I need to write update, insert and delete queries to update student's results.
I don't want to handle 3 queries. I am looking for more flexible way of doing this.
One solution, I came across is, update database manually. That is if the student is absent for any given subject, update results to 0 and keep the record. so in admin panel, I need to use only update query.I am not sure where this is ok from database concepts.
Is there any better solutions?
I didn't understand your question... may be this will be useful check this one
$var=1;
update tablename set col=col+$var
you can directly add value without retrieving previous value.

Double entry accounting database design [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Simple question
See http://homepages.tcp.co.uk/~m-wigley/gc_wp_ded.html
Ok there are 3 tables ACCOUNT, JOURNAL, and POSTING
If you want to have a transaction status, where should the status column be?
Status should be in the Journal table
Status should be in the Posting table
please explain your choice, thanks.
Simple, but trick question? There is no requirement for a success/failure status because a JOURNAL is a logical unit of work, and all of its POSTINGs are part of that unit of work. Therefore the JOURNAL and its POSTINGS either exist, if the logical unit of work is successful, or they don't exist if the unit of work is unsuccessful.
This simple test (it's there because it worked or it's not there because it didn't) is a consequence of the fact that there is a business requirement to ensure that JOURNAL includes a candidate key comprised of an unbroken sequence of numbers, which is necessary because it gives auditors a false sense of security.
In a real-world system, there would be a second set of tables, along the lines of PENDING_BATCH, PENDING_JOURNAL and PENDING_POSTING which would contain transactions that haven't been completed yet. It would make sense to keep various kinds of status information here. The transaction status for pending transactions belongs on the PENDING_JOURNAL table because the whole journal and all of its postings must either succeed or fail as a unit, so the status of the unit should be normalized to the parent record (i.e. PENDING_JOURNAL).

Resources