sql server - Variable length int columns in SQL -
I have a database with two tables: At this time, each The user is in a category. I want to change this so that each user is in any number of categories. What is the best way to do this? My site searches for very expensive, so the solution should be as efficient as possible. I really do not want to put the list of categories in every third table, because this means that when I pull back a search, then each user will appear in multiple rows at the same time (at least, this is what happens if I Existing, quite raw, has implemented a search with the understanding of SQL.) Edit: If there are many-many relationships to be established, then only one row each Use For Gkrta? For example: This will return a line for the user of each category. Is it possible to return only one line? At the moment you have one-to-many relationships, it is to say that with many users the category is added to the category But one user can be dependent with only one category. You need to convert it to many-to-many relationships so that each user can be attached with many categories and each category can be combined with multiple users. This can be achieved by adding a table that adds a user ID and a category id (and delete the vertical from the user table) For your final article, this is is the most effective way of modeling your requirement You will find a combination of PrimaryKey UserId / CategoryId in this table Make a user so that Ta to help prevent associated with that category. This prevents the user's problem twice for a particular category twice. To search for SQL, for example, all users associated with a category user and
categories .
Users These are the fields:
User IDs unique identifier user name nvarchar range iid int
DECLARE @SearchUserID nvarchar (200) = 1; Join the user from the selection JOIN CategoriesPerUser WHERE UserId = @SearchUserID
Table: UserTok Category UserIdInte CategoryIID Int
select u * User Uter YouTube User Tutorial on UK Usid Id = UK Usage where UK Edit the post after the comments: If you have a query that many users find, and you want a different list of categories related to those users, This can be done
SELECT c. * Categories from WHERE Category in IID (Usercock from SELECT uc.CategoryID and User User UUK UK User U = U.Userried where & lt; some criteria to filter users here & gt;)
Comments
Post a Comment