问题
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.
回答1:
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?
回答2:
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).
回答3:
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.
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/3610316/is-there-a-table-designer-for-vs2010-database-project