CREATE or ALTER PROCEDURE createdtatabase
(
@dbname VARCHAR(MAX)
)
AS
BEGIN
DECLARE @sql VARCHAR(max)=''
DECLARE @tblemployee VARCHAR(max)=''
DECLARE @tbldept VARCHAR(max)=''
SET @SQL = 'Create database '+@dbname
SET @tbldept='create table ['+@dbname+'].[dbo].[dept](
deptno int,
dname [nchar](10),
loc [nchar](10),
constraint pk_dept primary key (deptno)
)'
SET @tblemployee='create table ['+@dbname+'].[dbo].[emp]
(
empno int,
ename [nchar](10),
job [nchar](10),
mgr int,
hiredate date,
sal int,
comm int,
deptno int,
constraint pk_emp primary key (empno),
constraint fk_deptno foreign key (deptno) references dept (deptno)
)'
EXEC (@sql)
print @sql
EXEC (@tbldept)
print @tbldept
EXEC (@tblemployee)
print @tblemployee
END
--EXEC createdtatabase 'Newdb1'