Creating a database

A

Adrian

I am new to stored procedures.
Is the code below a stored procedure?
It doesn't have "CREATE PROCEDURE" in the code.
How should I incorporate the code below in a C#.NET application?

Thank you,
Adrian.

USE master
GO
CREATE DATABASE Products2
ON
( NAME = prods2_dat,
FILENAME = 'c:\program files\microsoft sql
server\mssql\data\prods2.mdf' )
GO
 
W

William \(Bill\) Vaughn

You clearly need to read one (any) of my books. This TSQL is used to create
a new database--not a stored procedure in the database.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
A

Adrian

So the referenced code isn't a stored procedure, ok. That was my #1
question.
I did mention that "It doesn't have "CREATE PROCEDURE" in the code."

My #2 question was how to incorporate the code into an application.
I would be very pleased to have the answer.

Many thanks.
Adrian.
 
W

William \(Bill\) Vaughn

Again Adrian, this kind of a question is like someone asking "Ok, I have
this knife... how is it that I'm supposed to take out my appendix?" I
(again) suggest that you do some basic research or take a class. I'll be
giving a class online on October 24th (and 25th) in the evening. It would
bring you up to speed on most of these subjects. I am also traveling to LA
(twice in the next 10 days) as well as 4 other cities all over the country.
These are all free conferences where I would have the time to get you
started in the right direction. See my website for my tour schedule.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
O

Otis Mukinfus

So the referenced code isn't a stored procedure, ok. That was my #1
question.
I did mention that "It doesn't have "CREATE PROCEDURE" in the code."

My #2 question was how to incorporate the code into an application.
I would be very pleased to have the answer.

Many thanks.
Adrian.

Adrian,

Ten years ago when I first encountered Relational databases I bought one of
Bill's books and it helped me get my feet on the ground. He's right about
getting a book to study. There is much to learn about working with databases and
it would be difficult for Bill or anyone to give you a good start by answering
your #2 question and the next 100 that will follow, so with no animosity, I say
get a book and work the examples in it until you have a bit more understanding
about the questions you are asking.

Bill writes good books and other folks do too. Go to the bookstore and browse
them. Then choose one that you feel is a good fit for you. You'll be surprised
how easy the basics will come to you.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
W

William \(Bill\) Vaughn

Thanks Otis. Incidentally, I have a new book about to be born--I'm currently
in labor. ;)
See www.hitchhikerguides.net . It has the most current information. I think
it's perfect for people that are just getting started as well as those who
have some experience but need to kown a lot more...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
A

Adrian

I have a text on Stored Procedures.

My questions were the following

(1.) The code below does not have "CREATE PROCEDURE" in it, as my text on SP
tells me Stored Procedures should have.
Question: "Is the code below a Stored Procedure after all?" Yes / No.

The code:

USE master
GO
CREATE DATABASE Products
ON
( NAME = prods_dat,
FILENAME = 'c:\program files\microsoft sql server\mssql\data\prods.mdf',
SIZE = 4,
MAXSIZE = 10,
FILEGROWTH = 1 )
GO

Answer "No"
(2.) The code has been taken from MDSN and is Transact SQL. If it isn't a SP
then I should be able to stick the code into a CommandText string and do an
ExecuteNocQuery. However if I want to create a database, that database is
not going to be there in the first place, so what do I put in the connect
string, since the connect string has to specify a database name?

Answer "Yes"
Question A.
Stored Proceduers seem to need "CREATE STORED PROCEDURE".
Question: how do I get the code to comply to the stored procedure cyntax?

Question B.
I can create a stored procedure from within the Server Explorer and from SQL
Server Manager Studio Express. From within VS I have to follow this route
according to a text I have: File -> New Project -> C# ->Database -> SQL
Server Project. I do not have these options in my VS Standard Edition. Is it
still possible to create a SP in my VS Standard Edition without these
options (not using the two methods I have already stated, viz: from within
the Server Explorer and from SQL Server Manager Studio Express)?
 
C

Cor Ligthert [MVP]

Adrian,

Try something as this from an old program of me,

cmd.CommandText = _
"CREATE PROCEDURE InsertMessage " & vbCrLf & _
"@Answer ntext, " & _
"@Problem nvarchar " & vbCrLf & _
"AS" & vbCrLf & _
"INSERT INTO tblMessages (Problem, Answer) VALUES (@Problem, @Answer)"
cmd.ExecuteNonQuery()

I hope this helps,

Cor
 
A

Adrian

Dank je Cor,
Adrian.

Cor Ligthert said:
Adrian,

Try something as this from an old program of me,

cmd.CommandText = _
"CREATE PROCEDURE InsertMessage " & vbCrLf & _
"@Answer ntext, " & _
"@Problem nvarchar " & vbCrLf & _
"AS" & vbCrLf & _
"INSERT INTO tblMessages (Problem, Answer) VALUES (@Problem, @Answer)"
cmd.ExecuteNonQuery()

I hope this helps,

Cor
 
R

Robert Porter

Whoa, I don't mean to be obnoxious so please don't take it that way, but
Williams analogy with the knife is correct. It is far easier to learn
something properly than blunder around and have to unlearn a lot. These
newsgroups are a great resource for answering all manner of questions,
but not for teaching the entire theory of relational databases AND a
complex environment like .NET.

Please do yourself a favor, find a local user group, or buy a beginning
book on SQL Server or take a class, you will save yourself a great deal
of pain in the long run.

We will be here to help once you get a base understanding.

Cheers,

Bob Porter
 
A

Adrian

Thank you all, much appreciated.
Adrian.

Robert Porter said:
Whoa, I don't mean to be obnoxious so please don't take it that way, but
Williams analogy with the knife is correct. It is far easier to learn
something properly than blunder around and have to unlearn a lot. These
newsgroups are a great resource for answering all manner of questions,
but not for teaching the entire theory of relational databases AND a
complex environment like .NET.

Please do yourself a favor, find a local user group, or buy a beginning
book on SQL Server or take a class, you will save yourself a great deal
of pain in the long run.

We will be here to help once you get a base understanding.

Cheers,

Bob Porter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top