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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter query HELP

Status
Not open for further replies.

KSiva

Programmer
Feb 18, 2002
63
AU
Hi all,

It's just simple question! How do I set a column as a primary key in SQL server 2000!

Can we simply use ALTER TABLE <t-name> ALTER COLUMN <c-name> ....

Or Do I need to set any constraint for this? And what's the syntax for that? None of SQL Server books teach me that.

And one more, How do I use sql statement to add VIEWS and STORED PROCEDURES?

Thanks,

Sivakumar Kandaraj :)
System Administrator,Web Programmer
Melbourne
Australia.
 
I realy good way to learn how to alter and create things in the database is to script an object in the Enterprise manager (you can also do it with the Query analyzer 2000). Just right click a table or an other object in the Enterprise manager and choose &quot;All tasks&quot; - &quot;Generate SQL-Script...&quot;.

To create a primary key:

ALTER TABLE [dbo].[TableName] ADD CONSTRAINT [aaaaaTableName_PK] PRIMARY KEY NONCLUSTERED
(
[ColumnName]
) ON [PRIMARY]
GO

To create a view:

CREATE VIEW dbo.ViewName
AS
SELECT
*
FROM
TableName
GO

To create a SP:

CREATE PROCEDURE dbo.usp_SpName
(
@nInputParameter int
)
AS
SELECT
*
FROM
TableName
WHERE
ID = @nInputParameter
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top