Is it possible / practical to add a constraint (i.e., Primary Key or Index) to a view?
I am using SQL Server 2000 and the view queries multiple tables across 2 databases.
I know how to add a constraint to the tables that host/build the view. Those indexes are there. They just don't seem to carry over to the view.
Thought? Ideas? Suggestions?
Thank you.
If your views don't violate any of the long list of requirements, you can create a clustered index on your view in SQL Server 2000, and thus speed up queries quite a bit.
See:
SQL Team: Indexed Views in SQL Server 2000
MSDN: Improving Performance with SQL Server 2000 Indexed Views
Anything else isn't supported, as far as I know - if you want a constraint, you need to constrain the underlying base tables.
If you have a concrete problem with a view, maybe you need to explain in more detail. What do your base tables look like? What kind of data (and how much) is in there? What does your view definition look like? What are the queries you run against that view, and how does it behave - is it "just slow" or do you get wrong results, or what's the issue?
Related
When I migrate from Access 2003 to SQL server 2019, I get half of the tables empty. What can cause this problem and how to fix this? Tables are not empty in Access.
Ok, so at least SOME tables are going to sql server. This is good, as it shows at least you have "some" of this working.
The tables that don't go? Often this is for two reasons.
the table(s) have bad dates - but SSMAA should spit out a error in that regards.
the other issue is if the table(s) in question have mutli-value fields (attachemnts, or a multi-select type of column. those columns are NOT supported and SQL server has no such data types, so they can't be migrated.
So, you might want to take a look at the offending table, see if any lookup-ups are defined for some of the fields (you can while in design mode - click on the lookup tab - see if a query exists). So, you need to un-convert such tables.
So, in the lookup tab, you see this:
So, as a general rule, you have to remove those columns. but, they are in fact a "hidden" table and relationship. So, in general you have to create a new child table, and fill out the related data BEFORE you migrate such data.
Can we do database partitioning (not table/view partition) on SQL server 2014 Standard Edition?
By doing database partitioning, I want to place files on different physical drives.
If not possible, please share link from site like Microsoft etc. mentioning that Standard Edition is not supported.
For all I know, in SQL Server you can put one or more tables in a filegroup, but you cannot break one table into multiple filegroups unless you are using partitioning. Since Standard Edition does not allow partitioning, it seems you are out of luck.
Now, I may regret saying this, but...
What you could consider is to mimic partitioning by splitting your stuff into two or more tables e.g. TABLE1, TABLE2, and so on. Then you place each table on a different filegroup. You can even create a view that does UNION ALL with the tables, so your SELECT queries can hit just one thing, though for INSERT or UPDATE you will probably need to go back to the tables.
Of course, this is NOT PARTITIONING, and you lose a lot of the benefits, from partition operations (switch, split, merge) to engine optimisation, to index management and surely other aspects.
In other words, I would not do this unless I know exactly what I'm doing.
I've been researching a bit on the use of indexed views and the noexpand hint in SQL Server and needed some clarification. Let's assume for this example you have two situations.
An indexed view is created against a table which already has an index created for the underlying table
An indexed view is created against a table which does not have an index created for the underlying table.
If we omit the noexpand hint, will SQL Server utilize the the view index in either situation? Or is noexpand only applicable when the table has an index and there is a choice to be made?
Secondly, does this behavior vary between editions of SQL Server? Has anything changed in 2012?
Depending what message board, blog, or MSDN documentation you read, it's a little unclear.
I'm trying to justify using EntityFramework and falling at the very first hurdle. I'm using the database first approach. Here is what it looks like in SQL Server 2008 R2:
As you can see, VERY simple domain. The association is a one-to-many relationship between User.Id and Blog.UserId.
However, even with this incredibly simple domain, EF fails. When I import the tables, I get this:
As you can see, there is no association. The relationship is gone and no matter how many times I delete, regenerate, it will not appear. "Include foreign key columns in the model" is checked.
However, if I create the tables based with keys based on ints instead of GUIDs, the relationships are created.
Is this a bug, a limitation or my own stupidity?
It doesn't inspire my confidence. How on earth will it perform in a real-life scenario, with a hundred tables and a thousand associations?
VS 2012
SQL Server 2008 R2
EF 5
I've resolved the issue. The problem was caused by a rogue index I did not know I had on the table.
If there is a UNIQUE index on the same field as the primary key, this will cause EF to fail to generate the PK-FK relationship at all.
Simply removing the unnecessary unique index (primary enforces unique anyway), the EF designer immediately picked up the relationship.
I was wondering if there was a way (relatively simple I hope) to get information about the table and its attributes and realtionships?
Clarification: I want to grab all tables in the database and get the meta-model for the whole database, tables, column data, indicies, unique constraints, relationships between tables etc.
The system has a data dictionary in sys.tables, sys.columns, sys.indexes and various other tables. You can query these tables to get metadata about the database structure. This posting has a script I wrote a few years ago to reverse engineer a database schema. If you take a look at it you can see some examples of how to use the system data dictionary tables.
there are a whole bunch of system views in the information_schema schema in sql server 2005+. is there anything in particular you're wanting?
some of those views include:
check_contraints,
columns,
tables,
views
Try sp_help <tablename>. This will show you foreign key refrences and data about the columns, etc - that is, if you are interested in a specific table, as your question seemed to indicate.
If using .NET code is an option SMO is the best way to do it.
It abstracts away all these system views and tables hiding them behind nice and easy to use classes and collections.
http://msdn.microsoft.com/en-us/library/ms162169.aspx
This is the same infrastructure SQL Server Management Studio uses itself. It even supports scripting.
Abstraction comes at a cost though so you need maximum performance you'd still have to use system views and custom SQL.
You can try to use this library db-meta