Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 create database with stored procedure

Author  Topic 

youness_casa18
Starting Member

3 Posts

Posted - 2011-04-27 : 07:59:07
hello to all here
how can I create a database by using stored procedure
this procedure is like this:

USE [master]
GO
create proc create_new_entreprise (@bd_name varchar(50))
as
begin
if not exists(select database_id from sys.databases where name =@bd_Name)
begin
exec('Create DATABASE'+' '+ @bd_Name)
begin
exec('USE'+' '+ @bd_Name)
create table avion
(
av int primary key,
avmarq varchar(30),
avtype varchar(30),
capacite int,
loc varchar(30)
)
create table pilote
(
pil int primary key,
pilnom varchar(30),
adr varchar(30)
)
create table Vol
(
vol varchar(100) primary key,
av int,
pil int,
vd varchar(30),
va varchar(30),
hd datetime,
ha datetime,
constraint fk_avion_vol foreign key (av) references avion (av),
constraint fk_pilote_vol foreign key (pil) references pilote (pil)
)

end
end
else
print 'la base des données est déjà existante '
end

if I try to excute this stored procedure i will have a empty database created and the tables wil created in the master database
for more information i use sqlserver 2008

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-27 : 08:06:40
Dupe, moved to correct forum: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=159920
Go to Top of Page
   

- Advertisement -