Using Variables When Creating A Database
May 3, 2007
I am trying to create a database using variables, so that the variables can be passed in when the script is run. But when I run the code below I keep on getting an error - any clues what I have done wrong? I’ve not used variables before, so sorry if it is obvious.
(NB The script was creating using the auto-create functions within SQL server)
DECLARE @database varchar(30)
SET @database = 'TESTdb'
USE [master]
GO
CREATE DATABASE [@database] ON PRIMARY
( NAME = N''+@database+'_dat', FILENAME = N'D:Data'+@database+'.mdf' , SIZE = 1932672KB , MAXSIZE = UNLIMITED, FILEGROWTH = 20%)
LOG ON
( NAME = N''+@database+'_log', FILENAME = N'L:LOGS'+@database+'_log.LDF' , SIZE = 8653056KB , MAXSIZE = UNLIMITED, FILEGROWTH = 20%)
COLLATE Latin1_General_CI_AS
GO
EXEC dbo.sp_dbcmptlevel @dbname=N@database, @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [@database].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [@database] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [@database] SET ANSI_NULLS OFF
GO
ALTER DATABASE [@database] SET ANSI_PADDING OFF
GO
ALTER DATABASE [@database] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [@database] SET ARITHABORT OFF
GO
ALTER DATABASE [@database] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [@database] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [@database] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [@database] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [@database] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [@database] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [@database] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [@database] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [@database] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [@database] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [@database] SET DISABLE_BROKER
GO
ALTER DATABASE [@database] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [@database] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [@database] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [@database] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [@database] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [@database] SET READ_WRITE
GO
ALTER DATABASE [@database] SET RECOVERY FULL
GO
ALTER DATABASE [@database] SET MULTI_USER
GO
ALTER DATABASE [@database] SET PAGE_VERIFY TORN_PAGE_DETECTION
GO
ALTER DATABASE [@database] SET DB_CHAINING OFF
View 2 Replies
ADVERTISEMENT
Apr 11, 2008
I have a dts package that has 4 global variables. Migrated the package to SSIS thru the wizard. But I need to fix the global variable in order to work.
This global variable is the path where the txt file is residing after you run the DTS package.
I want o know how could I create the global variable in SSIS?
View 1 Replies
View Related
Oct 5, 2006
Hi There,
I would like to know if for example i have some tables in my DataBase and i need from each table to get for instance, the Name by the ID, how can i make only one procedure which use parameters and variables so i can use this SP to get the Name By ID for all the Tables?
Thanks
View 1 Replies
View Related
Nov 12, 2007
Hello.
I need to store 2 values that i retrive from a databse into variables so i can check them towards what is typed into the textboxes for my login script iv built. How can i do this?1 string myConnectionString = @"Data Source=.SQLEXPRESS;AttachDbFilename=C:UsersalhoDocumentsIntrapointWebApp_DataIntrapoint.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
2
3 SqlConnection myConnection = new SqlConnection(myConnectionString);
4 SqlCommand cmd = new SqlCommand("SELECT [username], [password] FROM [company] WHERE (([username] = @username) AND ([password] = @password))");
5 cmd.Parameters.AddWithValue("username", TextBoxUsername.Text);
6 cmd.Parameters.AddWithValue("password", TextBoxPassword.Text);
7
8 myConnection.Open();
9
10 //how do i pass the values retrived into variables, like string usrname and string password?
11
12 myConnection.Close();
View 13 Replies
View Related
Feb 4, 1999
I have an installation script and want to create a database based on some data in a table (config). Testing the script though I get a message:
Msg 170, Level 15, State 1
Line 12: Incorrect syntax near '@DBData'.
The relevant sql is:
declare @DBName varchar (40)
declare @DBData varchar (40)
declare @DBLog varchar (40)
declare @DBSize int
select @DBName = obj_txt from config where obj_nm='DBName'
select @DBData = @DBName + '_Data'
select @DBLog = @DBName + '_Log'
select @DBSize = obj_int from config where obj_nm='DBSize'
raiserror('Creating Database %s ....',0,1,@DBName) with nowait
Create Database @DBName
on @DBData = @DBSize
Log on @DBLog = @DBSize
I don't think there's anything wrong, apart from the fact I am using the local variables. Is this allowed on a Create Database statement? I haven't found anything in Technet that may help.
Here's hoping....
Thanks
Dan
View 1 Replies
View Related
Aug 16, 2007
Here is my code
ALTER PROCEDURE Test
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @From varchar(10)
DECLARE @To varchar(10)
DECLARE @DBName varchar
SELECT TOP 1 @From = CONVERT(char,CreateDate,101) FROM CustomerInfo
WHERE TicketNum =
(SELECT TOP 1 TicketNum FROM CustomerInfo
WHERE CreateDate <= DATEADD(mm, -30, CURRENT_TIMESTAMP)
ORDER BY CreateDate DESC)
SELECT @To = CONVERT(char,GETDATE(),101)
SET @DBName = 'Archive_SafeHelp'
CREATE DATABASE @DBName + ' ' + @From + ' ' + @To
END
I am trying to create a database based on the name contained in the variables. I get the error 'Incorrect syntax near '@DBName'. How do i accomplish this?
Thanks
Ganesh
View 2 Replies
View Related
Sep 4, 2006
Hi,
I am not comfortable with DTS 2000 but I need to execute a encapsulated DTS 2000 package from a SSIS package. The real problem is when I need to pass SSIS variables to DTS 2000 package. The DTS 2000 package have 3 global variables that I can identify on " Execute DTS 2000 Package Task Editor - Inner Variables ". I believe the SSIS variables must be mapped on " Execute DTS 2000 Package Task Editor - OuterVariables ". How can I associate the SSIS variables(OuterVariables ) to "Inner Variables"? How can I do it? Much Thanks.
João
View 8 Replies
View Related
Jan 24, 2006
Hi,
I would like to design a SSIS package, which have couple of variables. It loads a xls file specified in a variable [varExcelFileFullPath] .
I will run it by commands: exec xp_cmdshell 'dtexec /SQL ....' (pls see an example below).
It seems it does not get the values passed in for those variables. I deployed the package to a sql server.
are there any grammar errors here? I copied it from dtexecui. It worked inside Dtexecui not in dos command.
exec xp_cmdshell 'dtexec /SQL "LoadExcelDB" /SERVER test /USER *** /PASSWORD ****
/MAXCONCURRENT " -1 " /CHECKPOINTING OFF /REPORTING EW
/LOGGER "{6AA833A1-E4B2-4431-831B-DE695049DC61}";"Test.SuperBowl"
/Set Package.Variables[User::varExcelFileName].Properties[Value];"TestAdHocLayer"
/Set Package.Variables[User::varExcelWorkbookName].Value;"Sheet1$"
/Set Package.Variables[User::varExcelFileFullPath].Value;"D: estshareTestAdHocLayer.xls"
/Set Package.Variables[User::varDestinationTableName].Value;"FeaturesTmp"
/Set Package.Variables[User::varPreSQLAction].Value;"delete from FeaturesTmp"
'
thanks,
Guangming
View 2 Replies
View Related
Nov 30, 2004
Hey Guys:
--- Not sure if this should be moved to webforms forum, or if it belongs here ---
Alright, I have been dealing with this issue for a few days now, and have found a few solutions but they all seem to throw different errors so I figured I'd ask here.
What i am trying to do is have a webform where user enter data, and have the data passed across forms, then displayed and inserted into a database on another form. THe first for has an asp:rangevalidator control dymamicly built so I cannot simply take of the tags and use the old style.
Eventually the user will be directed to a paypal form, and upon successful completion be redirected to the page with the insert command within it, but for now, passing it to a second page for review, then inserting it will work.
I am not sure how to accomplish this, a tutorial or a code example would be great!! I have though about panels, creating public objects, etc, but all the solutions I have found have one issue or another when I attempt to create them.
I'm using asp.net 1.1, VB.net and SQL server.
Thanks,
Brian Sierakowski
View 1 Replies
View Related
Jul 3, 2014
I have finally been able to get access to SQL Server 2012, so I am just now getting to play with some of the features. My new company has multiple ways of calling an SSIS package, and some (if not all) use Package Parameters. I just did a little research on these, and I in general get how they work. Here is why I ask...
I liked how my last company had dynamic variables setup. They had all of the required variables stored on a single database table on a single server. This kept all of the connections strings, file paths, file names, etc. that a package would use. My computer, the UAT server, and the Prod server all had the same file in the same location with 1 character difference to note which environment to run in. This way I knew I would always use only the Dev server when I ran a package during development. I would also only touch the test folders with my test data. Once we moved it to UAT or Prod, that single character difference would point to a different set of variables for the same PackageID, and we didn't have to worry about forgetting to change hard coded variable values. The only 2 hard coded variable values were the PackageID and the variable holder database. I have heard of similar ways of doing this via an XML file, but I have not had the (ahem) pleasure of working with that yet.
Jump to my current job and why so far I have not been impressed with the Package Parameters. We have 3 different jobs that all call the same SSIS package. We feed in a different FacilityID, and using values stored in tables we know to look for different file names, etc. To me this seems to be a similar set up to how my last company had set the system. The big difference is my old company used a Script Task to verify which environment we were running in (I can see setting this for different FacilityID's, but that would be cumbersome), and my new company uses multiple tables across multiple databases (I know, this is not the best set up in the world, and we are fixing it soon) to decide what we will use for some of the variable values.
What are your thoughts on storing variables outside a package? Do you have any blog posts or articles you can link to show current best practices?do the Package Parameters only work via the Integrated Services Catalog, or can they be accessed for the File System packages too?
View 2 Replies
View Related
Nov 24, 2006
Hi guys, can I know the steps on creating a database snapshot on a mirror database? Thx for the assistance. :)
Best Regards,
Hans
View 1 Replies
View Related
Feb 19, 2007
Hi
when I run this query against an Oracle 9 datasource I get a message saying 'not all variables bound'
select <some fields> from star
where nr_jahr_star = :Year
my datasource is correct as the same report runs fine if I just put in a fixed year and I have the Oracle client software on both my PC and the RS server
I've tried various combinations with the parameter settings also with no luck.
Thanks
Steven
View 1 Replies
View Related
Jun 26, 2006
How do you create a SQL database (Sql Express 2005) in real time using VB.Net 2005 ASP.net 2.0?
View 2 Replies
View Related
Dec 4, 2007
I am working on site in asp.net with c# and using database sql server 2000 and managing all the data on server i have created one database on server and in that i have created 15 table. should i continue with the same or create another database for table.
tell me how many tables should i maintain in one database. and what precausion should i take while mainting database to increse the speed of site.and what precausion should i take to avoid serverload
please guide me i dont have an idea.
thanks for spending ur valuable time for me.
View 8 Replies
View Related
Nov 21, 2003
Sorry, I'm a newbie out there when it comes to creating database. I currently have an ASP.Net project which requires a database. I spent the past few days thinking about how to create a proper database for the application but to no avail. I think tis thread might be out of point for tis forum, but i am really in need of help.
Here goes the storyline of my database:
The project is an online project management system, meant for students to submit their deliverables (reports, eg. Minutes, agenda, project monitor chart) Lecturers will access the web application to grade the student’s submission. The application must allow administrators to add in new subjects. When a new subject is added, the subject leader will set a dateline for a particular module to be submitted. Eg, minutes dateline. Once the dateline is due, the system will inform the lecturers in charge of who/which group did not submit the module. Lecturers and subject leaders can then generate warning letters to be sent via email to the students involved. Lecturers and subject leaders will be able to make announcements through the system as well.
A student can either submit his/her work as an individual or as a group.
A student will be studying more than 1 subject.
A subject will consist of more than 1 module.
Every module will have a dateline for its submission.
Students can make more than 1 submission for each module.
Students belong to different groups/classes for different subjects.
For different modules, there will be different fields to be inserted into the database.
Example, in the “Minutes module�, the student will have to be able to key in the objectives, the date of the meeting, the venue, its members, absent members, actual minutes, action by and meeting end time.
In the “Project monitor chart module�, the student will have to key in the week/date, the name of the member, task involved, as well as the status.
When a new subject is created, the subject leader will have to specify the percentage of each different module. (Eg, Exams – 40%, Term test 15%, and so on.)
A subject will also be taught by more than 1 lecturer. So subject leader will specify the lecturers teaching that particular subject.
I hope someone out there can help me out on the construction of a database for the above storyline. Thanks a lot.
View 1 Replies
View Related
Jan 14, 2004
Hi All,
Can anybody help me/does anybody have the code to create a database on ms sql server 2000 using asp.net?
This needs to be done without being asked for the sql server login credentials (i.e the sa username/password can be inserted in the code)
View 8 Replies
View Related
Aug 19, 2005
Is there any tools to create a database with tables, views, and all that jazz with a GUI. I went through the exammle on beta.asp.net but the way they created their db was with a script. I want to create everything with a GUI app. If this gui app doesn't exist can someone point me to where I can find more info about creating db, tables etc with sql server 2005 express? Thanks in advance.-Daticus
View 2 Replies
View Related
Oct 14, 2006
I have an excel document that Imported to access database. That database should count the number of tickets created by each tech rep; list the area, sub area and description of call created by a the tech rep. Can access perform this task and if yes, any idea I to approach that project or should i use SQL, And if access won't be able to do it. please make a suggestion how to approach this project. it will be nice if i can get the steps.
EXAMPLE
Request Id SRS Started Call Description Area Sub Area Request Status Closed Date Assign To Created By
View 2 Replies
View Related
Apr 12, 2004
I created a database using the following command :
create database krish on (Name='krish', filename='C:Program FilesMicrosoft SQL ServerMSSQLdatakrish.mdf', size=25, maxsize=50,filegrowth=5%)
This actually created the database. Now, I wanted to view this database info being stored inside the SQL Server system tables. I looked at "sysdatabases" table and found an entry as expected for "krish" but I could not trace where the info corresponding to the size of the database was stored ie.25MB . (I looked ad "sysdevices" but couldn't find any entry for the newly created database).
In which table is it stored ?
Any help is appreciated.
View 2 Replies
View Related
Jan 30, 2007
suppose if we want to create a database and all it relative things to a new server , for that if we restore the backup copy of that databas in a new server will it create the database and restore the data.
Is it enough to restore the backup copy or we need to restore the log also.
View 2 Replies
View Related
Jun 11, 2007
I've done a lot of stored procs and modified tables but now I need to create a very basic database from scratch and wonder on how the best way to get started or any good tutorials out there.
I need a db with the following
Content Table
Customer Table
User Table
View 1 Replies
View Related
Nov 26, 2007
Hello everybody, my name is Andy,
I need help for creating a database, it's an exercise for my school, we just began to learn SQL, about entities, relationships (one to one, one to many...), creating tables, but the thing is i don't know where to start, i think i need to practise but it's hard to transform a text into a database, i think i need some help from you guys and i hope you will help me.
I give you the exercise, and what i found :
Project wants users to be able to initiate debates, post articles and get to the achieved items. A user should be able to write as many articles as desired after having register with login and passport
However articles should contain these references for more http links, URL, summary of the content; 1 or more books, article, doc, case studies …
1)Identify the data objects and relationship and draft the initial ER Diagram with entities and relationships. Normalize model as far as you can
2)write the SQL query / link (url) and corresponding summary
About the 1)
Entities : users --> login and password associated (one to one relationships one user = one login/password)
Articles --> associated with the users accounts (one to many)
I am not sure for creating the different tables, im a bit lost... :s
About the 2) totally lost, i need the 1) to make the SQL Query (i know a bit about queries)
I hope you will help me, i am a beginner in SQL (only one course taken) and it is our first exercise, thanks for your help all!!!
View 2 Replies
View Related
Feb 20, 2008
Hi,
I am developing a Translator for a Mobile Phone and i have to create a database for storing English, Esperanto and French words. What are the SQL statements should i write to create the database and how can i deploy the database in a Mobile Phone/PDA?
View 1 Replies
View Related
Dec 16, 2006
Hi,
I have a test database running on the server. Now what I want to do is to create a dev db that has the exact same data model as the test one so that I can test out my application on the dev db and then migrate it to the test db. Can somebody tell me how I can achieve something like that.
Thanks...
View 1 Replies
View Related
May 12, 2006
OK,
I have downloaded and installed 2005 express. All I want to do now is create a new database. I do not see where to do that. All that was installed was the SQL Server Configuration Manager and the Surface Area configuration. Am I missing something. I guess I am looking for something similar to Enterprise Manager. Where is it?
View 4 Replies
View Related
Oct 16, 2007
I'm rusty with database design just yet so trying to improve. This is my way of creating a database in Access but before i swap over to SQL structure i would like a good foundation.
Overall the way i looked at it was you had to have one table that held all your results that users entered and the query took care of the rest??? So for example (Red indicates a Primary Key)
tbl_Products
ProductID
ProductCode
ProductDescription
ProductUnit
ProductQuantity
ProductPrice
tbl_Month
MonthID
Month
tbl_year
YearID
Year
tbl_Department
DepartmentID
DepartmentName
tbl_Employee
EmployeeID
EmployeeFirstname
EmployeeLastname
tbl_Orders
OrderID
OrderProductCode
OrderProductDescription
OrderProductUnit
OrderProductQty
OrderProductPrice
OrderMonth
OrderYear
OrderDepartment
OrderEmployee
I then have the following relationships (1 to Many):
ProductCode (1) - OrderProductCode (Many)
MonthID (1) - OrderMonth (Many)
YearID (1) - OrderYear (Many)
DepartmentID (1) - OrderDepartment (Many)
EmployeeID (1) - OrderEmployee (Many)
Ok your'e probably thinking what if i need to add another Employee or how would i retrieve Employee or month details - to add another Employee the user would have to enter the details on another form which allows them to add another Employee. To select an Employee on the Order Form i would create a combo box which allows the user to pick an Employee.
To create a query to pull product Code, Description, qty, price and Employee name (to see which employee placed the order) i would add the following to a query
ProductCode (From tbl_Products)
OrderProductDescription (From tbl_Orders)
OrderProductQty (From tbl_Orders)
OrderProductPrice (From tbl_Orders)
EmployeeFirstname (From tbl_Employee)
EmployeeLastname (From tbl_Employee)
This is the way i thought you should create a database but i'm a developer therefore only work with databases when the query is created by a db admin. Guess i have something wrong here?? if so how would you go about creating this type of database? Overall purpose of the database is usually a user entering data and retrieving data every so often.
Thanks in advance.
View 4 Replies
View Related
Oct 13, 2015
I am developing a test solution using Visual Studio and need a sql database. I have sql Management Studio (2008 & 2014) but when I try to create the database I get an error saying I need administrator permissions (or similar). This is a personal laptop with only me as a user and I AM the administrator.How do I create the database?
View 6 Replies
View Related
Aug 15, 2006
Hi. Im brand new to using SQL. I downloaded the SQL Server 2005 Trial Edition (Enterprise Evaluation Edition) and installed it. How do i create a database ? The only thing i can seem to open is the SQL Server Configuration Manager which just lets me start the Server. Did I install it wrong or open the wrong program? If someone could help I would greatly appreciate it.
View 10 Replies
View Related
Jul 13, 2006
I have been using microsoft office access to create database and connect to application built. This is the first time trying to create database using the sql server. How do i create a database using this?
Do i use the sql server management to create it?
Is there any step by step tutorials?
How do i connect the database to the web developer?
View 5 Replies
View Related
Aug 30, 2006
I've seen several post asking for that possibility, but all 've read, didn't help me.Some sing SQLDMO, other suggest to use SQLSMO, others only explaining to connect to a server and then do "CREATE DATABASE".I will do this within .Net. Connecting to a SQL Server 2005 and execute "CREATE DATABASE" I could realize.But how doing this with SQLExpress? Trying to do SqlConnection.Open with a non existing DB does not work., says "file not exists".Or do I only have the wrong connection string? Can someone post here an excample connection string, which works with a non existing database?Some hints I've read make me considering to use SQLSMO. But I don't have it on my computer. Where do I get it from? Any links would be nice.
View 6 Replies
View Related
Dec 29, 2006
I've tried copying the tutorials and this is the result:
test6 below is accepted:
CREATE TABLE test6(id smallint,first_name nvarchar(50) NOT NULL,last_name nvarchar(50) NOT NULL,movie nvarchar(50) NOT NULL,PRIMARY KEY(id));
test7 below is rejected:
CREATE TABLE test7(id smallint auto_increment,first_name nvarchar(50) NOT NULL,last_name nvarchar(50) NOT NULL,movie nvarchar(50) NOT NULL,PRIMARY KEY(id));
My provider is GoDaddy, the error message is -2147217900, with "Line 2: Incorrect syntax near 'auto_increment'.
View 2 Replies
View Related
Feb 9, 2007
I've made a form and now all I want to do is save everything in the form into a new database file but I don't know how. I'm using Visual Web Developer 2005. Somehow I'm guessing that I have to set something somewhere so when the submit button is hit, it knows to save it to a database file which doesn't exist yet so it would have to create it. It should be easy but I can't figure it out.
View 1 Replies
View Related
Dec 6, 2007
Hi,
I have my MSSQL database developed in Visual Web Developer 2005 Express Edition. I am trying to create a backup file of this databse (.bak). Is SQL Server 2005 Studio Express the program that will let me do this?
Also in SQL Server, how can I attach to my database that I have made in Web Developer 2005? if I go to attach it doesn't list anything.
Thanks for any help.
View 1 Replies
View Related