Visual Studio Database Pro Partial Projects Constraints Issue - visual-studio-dbpro

In Visual Studio 2008 Database edition one can use "partial projects" to allow a database to be separated into multiple projects for deployment and maintainability. I have been looking into doing this with our project but hit the following snag:
If you have project that defines some base tables, and then you have a different project that defines a new set of tables that have constraints pointing to the tables in the first project, DBPro seems unable to map this relationship. The specific error is:
"CONSTRAINT has an unresolved reference to Table foo" (where foo is in the original DB).
A more concrete example if you'd like to duplicate for yourself the scenario:
Create a Project called BaseDB.
Define in BaseDB a table called Users with the following DDL:
CREATE TABLE [dbo].[Users] (
UserID INT IDENTITY(1,1) PRIMARY KEY,
UserName NVARCHAR(20) NOT NULL
)
Export BaseDB as a partial project adding the _BaseDB.files file to your project.
Create a Project in the same solution called DerivedDB
Use the Import Partial Project to point to BaseDB, confirming if you like that there's a stub reference in your import files pointing to the Users table in BaseDB.
Define a table in DerivedDB called PowerUsers with the following DDL:
CREATE TABLE [dbo].[PowerUsers] (
PowerUserID INT IDENTITY(1,1) PRIMARY KEY,
UserID INT NOT NULL
)
If you do a "Build" at this point, everything works.
Add a FOREIGN KEY CONSTRAINT in the DerivedDB project from PowerUsers to Users with the following DDL:
ALTER TABLE [dbo].[PowerUsers]
ADD CONSTRAINT [PowerUsers_Users_FK]
FOREIGN KEY (UserID)
REFERENCES [dbo].[Users] (UserID)
Performing the above steps should allow you to see the error I'm talking about.
Questions:
Is there a way to fix constraint references across database projects?
If not, should partial projects then be reserved for series of stored procedures and the base project reserved for all DDL of base tables and constraints?

Related

How to create form/report on a table which has only primary keys?

Im trying to create a form with a report on a table that has only primary keys.
I have a table:
create table WRITE
(
author varchar(5) references AUTHOR (authorcode) ,
book varchar(20) references BOOK (bookid),
primary key(author,book)
);
I'm using APEX Application Builder to create a form on a table with report;
But When I get to the "Select the columns to include in the form" , I have no options to select from because I only have unique primary keys in my table.
Which Apex version is it? I've tried it on apex.oracle.com which uses 19.1 and it doesn't have that problem.
Anyway, two options I can think of:
temporarily drop primary key constraint
then create report + form pages
after you're done, create the primary key constraint once again
create an interactive report (using the wizard)
then create a form, manually adding items
this isn't as easy as it looks like because you'll have to create all processes as well (initialization one, along with automatic row processing)
I presume that the first option is a lot simpler.

Updating a SQL Server database using Entity Framework is not pulling in new tables

I created a database in Azure and have it working just fine in my project.
I went to extend it today and discovered I'm unable to "Update database" in the .edmx file.
The new table has a PK.
So I created a very based test table and have the same issues with it. This is the table I created:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestTable]
(
[Id] NVARCHAR(128) NOT NULL,
[Testcolumn] NVARCHAR(256) NOT NULL
);
GO
CREATE UNIQUE NONCLUSTERED INDEX [UserNameIndex]
ON [dbo].[TestTable]([Testcolumn] ASC);
GO
ALTER TABLE [dbo].[TestTable]
ADD CONSTRAINT [PK_dbo.TestTable] PRIMARY KEY CLUSTERED ([Id] ASC);
So again, after creating the table I go into the .edmx and click on update model from database and the new table(s) do not show up in Visual Studio 2017.
Anyone know what could be wrong?
Update:
it gets even weirder. I created a new model and updated from the database and the tables came down. I still can't update the original model though. I don't want the solution to be deleting the model and re-creating it because down the road that is not going to be a good idea.
I had to completely delete the model and recreate it. That was the only thing that fixed it. Nothing to do with the table configuration at all.
EF requires that your table has s Primary key, and that is not the case.

Oracle designer - table definition

I've added a new table definition to a project folder and then created a primary key, however when I click on the 'columns' to create a key component its telling me no mandatory columns are in the Table Definition - create one or more mandatory columns. I've gone back to table definitions but I can't see how I do this and then assign columns to the Primary key?
Any help appreciated!!

Is there a table designer for VS2010 database project?

Am I missing something here? It seems that the only options to create a new table in a database project in VS2010 is:
Create a table object as a file, then create all constraints (defaults) as separate files, then create each index as a separate file, and primary key as a separate file and on and on...
Or
Create the entire table schema using the table designer in SSMS and then use the schema compare tool to create a single monolithic file of SQL statements for each element of the table and copy each block of code to a newly created file in VS.
This question was asked 2 years ago and I'm hoping the answer has changed.
Please tell me there's a hidden table designer for the database project in VS2010 that I have just overlooked.
I'm pretty sure there isn't one!
Can I ask why you need a table designer over creating and modifying creation script files for your new objects? Is there anything that this doesn't give you that a designer would?
I just noticed that VS 11 Beta now includes a designer, although it is rough around the edges (relationships, for example, still need to be typed by hand).
The way I use the database project in VS2010 is:
Create everything with SQL Server Management Studio.
Synchronize it into my database project.
When I need to change something, do it in SQL Server Management Studio.
Use Schema Comparisons to synchronize your database project.
Wow... can't believe no one has taken the time to answer this in all this time. Here's a sample of table creation script with some simple constraints.
CREATE TABLE [User]
(
UserID INT NOT NULL IDENTITY (1,1),
UserName NVARCHAR(20) NOT NULL,
UserPassword NVARCHAR(20) NOT NULL,
EmailAddress NVARCHAR(50) NOT NULL,
Location NVARCHAR(100),
MobileNumber VARCHAR(10),
CreatedDate DATETIME NOT NULL
CONSTRAINT User_CreatedDate_DF DEFAULT (GETDATE()),
CONSTRAINT User_UserID_PK PRIMARY KEY CLUSTERED (UserID),
CONSTRAINT User_UserName_UQ UNIQUE (UserName),
CONSTRAINT User_EmailAddress_CK CHECK (EmailAddress LIKE '%#%.%'),
CONSTRAINT User_MobileNumber_CK CHECK (MobileNumber LIKE '[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]')
)
You can use functions to embed in your check constraints, but again, this is a simplistic exaxmple.
As I commented here, the VS2010 reference states that there exist a Table Designer in this document.
But for some reason, no matter what kind of project I create (Server project 2008/2005, database project 2008/2005) I can't get the Table Designer being shown.

Linq2Sql: Can I create entities with foreign key relationships without a primary key in both tables?

I have 2 tables in my database that I'm trying to create Linq2Sql entities for. There's more to them than this, but this is essentially what they come down to:
Rooms UserActivity
-------- --------
RoomID ActivityID
RoomID (foreign key on Rooms.RoomID)
The UserActivity table is essentially just a log for actions a user performs against the Rooms table.
Since the UserActivity table is only used for logging actions taken, it didn't make a lot of sense (to me at least) to create a primary key for the table originally, until the Linq2Sql mapper refused to make UserActivity a part of the Room entity in my Linq entities. When I set up the entities in the Visual Studio designer, I got these 2 warnings:
Warning 1 DBML1062: The Type attribute 'UserActivity' of the Association element 'Room_UserActivity' of the Type element 'Room' does not have a primary key. No code will be generated for the association.
Warning 2 DBML1011: The Type element 'UserActivity' contains the Association element 'Room_UserActivity' but does not have a primary key. No code will be generated for the association.
These warnings led me to create the ActivityID column in my table as displayed above.
What I'd like to know is if there is any way to allow Linq2Sql to create relationships between my entities without having a primary key in both tables. If I don't have the primary key in the UserActivity table, the entities can still be created, but the relationships aren't generated.
Is is it possible to do this, or should I try to make sure my tables always have a primary key in them as a general good practice?
Any table that stores real data in your app should always have a primary key - most cases, in SQL Server environments, a INT IDENTITY(1,1) will be just fine. You don't have to keep track of those, no bookkeeping necessary etc. It doesn't cost you much, totally easy to do - I don't see any reason why not have a primary key, even on your UserActivity table.
ALTER TABLE UserActivity
ADD UserActivityID INT IDENTITY(1,1)
CONSTRAINT PK_UserActivity PRIMARY KEY
and you're done!
The only time I would say no primary key is needed is for things like temporary tables when bulk importing huge amounts of data, or other temporary scenarios.
Marc
You need a primary key to create relationships.
It's good practise to always design tables with primary keys, even if you add surrogate (auto increment identity).

Resources