can u set a SQL table constraint from within VS.NET?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have an table on an SQL server and need to set a constraint like do not allow an insertion of a record of the first field (a varchar) matches any of the existing records. Just wondering if this can be done from within .NET? I think it can be done from the enterprise manager tool but not sure.
Thanks.
 
Any constraints on database tables need to be implemented in the
database itself. You can create a unique constraint as part of a
CREATE or ALTER TABLE statement, or by using the Enterprise Manager.

--Mary
 
I agree, in that I wouldn't use anything .NET-based to create that
constraint and/or primary key. If you were using a disconnected DataSet,
you could create similar logic- but that would only be for the DataSet
itself, and not for the database (SQL Server, Oracle, etc). When you
reconnect the DataSet, the database itself would still be "king" over
constraints and keys. Any duplicate row would be rejected by the database,
and you'd have to set up exception handling in the Dataset to handle that
situation.

-Thomas

Mary Chipman said:
Any constraints on database tables need to be implemented in the
database itself. You can create a unique constraint as part of a
CREATE or ALTER TABLE statement, or by using the Enterprise Manager.

--Mary
not allow an insertion of a record of the first field (a varchar) matches
any of the existing records. Just wondering if this can be done from within
..NET? I think it can be done from the enterprise manager tool but not sure.
 
Hi Tom, Mary, thanks for the information. I ended up accessing the same menu as shown in the Enterprise manager but from the .NET environment by openning the server explorer and then going the database and open the table. Next I selected the Database-design table selection and right click anywhere in the window. Finally I selected indexes and keys and set table constraints there, which is the same menu as shown in Enterprise manager and effects the database directly.
 
If you are solely responsible for database development, you should be
aware that not all of the functionality of the Enterprise Manager or
other SQLS client tools is available from the VS.NET UI. Implementing
security, query optimization, debugging and other tasks are best
performed using the SQLS client tools.

--Mary
 
Database design is the most important part of the application -- get
that wrong and nothing you do on the coding end will make any
difference. I'd recommend Mike Hernandez book, Database Design for
Mere Mortals, which is written for the business developer. Picking up
a good book on using SQL Server isn't a bad idea, either -- there's
lots of them out there. Kalen Delaney's Inside SQL Server is an
excellent reference on SQLS internals. To answer your question, query
optimization is the process of determining appropriate indexes for
complex queries that might otherwise run slowly. The Query Analyzer,
which is part of the SQLS client toolset, has a wizard that walks you
through the process.

--Mary
 
I completely agree (again)! At the least, draw an E-R diagram
(entity/relationship) diagram. All your business logic must fit into that
diagram. It's okay to deviate from database form (such as 3NF), but in
general, you should try your hardest to fit your requirements into a schema
that doesn't allow duplication. If you can't simulate your program/business
logic from that ER diagram, like Mary said, your coding will turn into a
mess. And once you're in production, with live data, you won't want to
start dropping/recreating tables and constraints!

Also, make sure you're consistant with your object names... for example,
don't use a primary key of "OrderID" in one table while calling it "OID" in
another table- use "OrderID" for both. This especially helps for those
"automatic" mapping programs, such as Crystal Reports. (I believe VS.NET
does something similar in Visio?)

99.9% of my experience is with Oracle, and rather than rely on Oracle's
Enterprise Manager to design a database, I always write up SQL scripts. The
benefit is that I only have to write (and document) the script once for my
development server- when I'm ready to move to production, I just run the
exact same SQL scripts on the production rdbms. I believe that the SQL
Server equivilant of Oracle's SQL*Plus is Transact-SQL.

-Thomas

Mary Chipman said:
Database design is the most important part of the application -- get
that wrong and nothing you do on the coding end will make any
difference. I'd recommend Mike Hernandez book, Database Design for
[..snip..]
--Mary

Hi thanks for the information. Kind of new to database design so hoping
to start using the Enterprise manager soon. Also not sure what query
optimization is? It would be nice to be able to step through stored
procedures as well which I have not been able to do when running a .NET
application that calls the procedure.
 
Back
Top