Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is this correct?

Status
Not open for further replies.

dakoz

Programmer
Feb 2, 2002
74
0
0
im new in sql and i'd like 2 ask if this is correct or
if there is another way to do it?

CREATE TABLE [Topics] (
[Topic_Code] [int] NOT NULL ,
[Topic_Name] [char] (30) NOT NULL
)

The following SQL code creates the constraints for this table:

ALTER TABLE [Topics] WITH NOCHECK ADD
CONSTRAINT [PK_Topics] PRIMARY KEY CLUSTERED
(
[Topic_Code]
)

ALTER TABLE [Topics] WITH NOCHECK ADD
CONSTRAINT [CK_Topics] CHECK ([Topic_Code] >= 1 and [Topic_Code] <= 8)

The SQL code that we used in order to create this table is as follows:
CREATE TABLE [Referees] (
[Referee_ID] [int] NOT NULL ,
[Topic_responsible] [int] NOT NULL ,
[LastName] [char] (30) NOT NULL ,
[Middle] [char] (10) NULL ,
[Firstname] [char] (30) NOT NULL ,
[Phonenumber] [char] (20) NULL ,
[Address] [char] (60) NULL
)
The following SQL code creates the constraints for this table:

ALTER TABLE [Referees] WITH NOCHECK ADD
CONSTRAINT [PK_Referees] PRIMARY KEY CLUSTERED
(
[Referee_ID]
)

ALTER TABLE [Referees] WITH NOCHECK ADD
CONSTRAINT [IX_Referees] UNIQUE NONCLUSTERED
(
[Topic_responsible]
)
 
Hi

The above appears correct, but there is a far easier way.

Open SQL Server Enterprise Manager

Find your database in the treeview on the left

Click on the tables node below your database

In the right hand pane Right-Click and Select Add Table

This will give you a grid which allows you to specify your fields and constraints.

When you exit you will be asked for a table name, and prompted to save.

To change the design in future right-click on your new table and select Design Table.

Hope this helps

Regards

Sadcow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top