sql - Create a DATABASE using as a Name from a Variable -
I want to create a database using a variable using Valuable. Here's my script but it does not work. any idea?
- Set Data Base name DECLARE @ DataBaseName char (64); SET @ database name = 'DBCSSWiteTest'; - Create database of data base @ Database name;
You think I need dynamic SQL for this (with proper caution if name is given by user)
- Set Data Base name DECLARE @ DataBaseName sysname; SET @ database name = 'DBCSSWiteTest'; IF (@ DataAbaseName '% [^ 0- 9A-Z]%') Receiver ('name,% s', 16,1, like 'invalid characters in databasebase') ELSE BEGIN SET @ DataBaseName = QUOTENAME (@DatabaseBaseName) EXEC ('Create Database' + @ Database Name) END
Comments
Post a Comment