Problem In Creating Database And Table In One Shot

May 9, 2006

I need to create a database and then create tables in it..

 IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'DB1')
 DROP DATABASE [DB1]

 -- create a new database
 CREATE DATABASE [DB1] ON  PRIMARY 
 ( NAME = N'DB1', FILENAME = N'D:DB1.mdf' ,
SIZE = 51200KB , MAXSIZE = UNLIMITED, FILEGROWTH = 30720KB )
  LOG ON
 ( NAME = N'DB1_log', FILENAME = N'D:DB1_log.ldf' , SIZE = 2048KB , MAXSIZE = UNLIMITED , FILEGROWTH = 30720KB )
  COLLATE Latin1_General_CI_AS


CREATE TABLE [DB1].[dbo].[SALES](
    [PERIOD] [int] NOT NULL,
    [LOC] [nchar](3) COLLATE Latin1_General_CI_AS NOT NULL
   ) ON [PRIMARY]


If i run the above statement one after one, they work; however, if I run all of them together (or in sp), the following error raised:

Msg 2702, Level 16, State 2, Line 43
Database 'DB1' does not exist.

May I know how can i create a database and then immediately the tables in sp!

Thanks

View 5 Replies


ADVERTISEMENT

How To Set Store Procs And Table Rigths In One Shot ??

Jan 22, 2008

Dear all,

I am not so in database administration and I wold like to get some glue how to do what I am looking for.
I have a set of procedure and view in my Database HISTORY, then I define Grant the Execute rights to all those procedure for user NTAuthorityNETWORKSERVICE.

Then I have a second database named CONFIG where table might be accessed by store procedure of the database HISTORY. So first of all, in addition to set the EXECUTE grant access to my strore proces of database HISTORY, I need to set the SELECT grant access to all tables from database CONFIG on which are access by my storeprocs of database HISTORY.

First of all is it correct to set rights like this ?

Second, is there a way to set the access right of all my desire procedure in one shot ( script or something else ) becasue I have doen it manually and its painfull ?
If yes how to do that

thanks for help
regards
serge

View 4 Replies View Related

Creating A Table In Database?

Nov 28, 2014

I am having problems creating a table in my first database.

When I script:

CREATE TABLE ship (mmsi INT, time INT, longitude INT, latitude INT, cog INT, sog INT, heading INT, navsat INT, imo INT, name CHAR, callsign VARCHAR, type INT, a INT, b INT, c INT, d INT, draught INT, dest CHAR, eta INT); I am returned with an error 1064 with regads to the attributes from "Typ" onwards.

From what I can see this should work.

View 3 Replies View Related

Creating A Table Using Data From Another Database

Jan 25, 2007

hi, i'm trying to create a table and populate it with data from another database residing on the same server. i've done this on oracle using tables within the same database and am just making a first effort with the added twist of a different database. this is what i've been doing so far...

CREATE TABLE facility_dimension
(
fac_id INT IDENTITY(1,1),
tri_fac_id CHAR(17),
fac_nameVARCHAR(100),
street VARCHAR(100),
city VARCHAR(100),
county VARCHAR(50),
state VARCHAR(4),
longitude REAL,
latitude REAL,
PRIMARY KEY(fac_id)
)
SELECT tri_facility_id, facility_name, street_address,
city_name, county_name, state_abbr, fac_latitude,
fac_longitude
FROM TRI_2004.form_1;

....where TRI_2004 is the other database and form_1 is the table. the result is creation of the new table and then the output of the secondary query. i'm assuming this can even be done but if it can't that would be helpful to know as well. thanks in advance!

View 2 Replies View Related

Error Message While Creating Table In The Database

Jan 25, 2005

Hi

I created database using SQL server and runs under Cassini. The creation of database is ok but I have a problem when I am creating the table in database. Whenever I execute the code to create the tables, it shows the error message like 'Server not found' or just hang there. Does anybody know why it hang while I am creating the table? Is it because of the code or it's the time out error. Pls help as I am very new to this area.

MZ

View 1 Replies View Related

Creating Database And Table On MS MSQL Server

Jul 20, 2005

Hi All,I want to use MS sql server edition 2000. I have installed the server. Now iwant to create the database on this server with tables and triggers. Canplease someone suggest me how to do this ?Thanks a lot,Dinesh

View 1 Replies View Related

Transact SQL :: Creating Table In Particular Database When Run Dynamic Script

May 13, 2015

I have a question regarding the dynamic sql. I have a script which which deletes all the foreign keys and re- creates it. So, I have created a table instead of a temp table. Now I need to create that foreign keys table in such a way that in which ever database I run the script, this  foreign keys table should be created in that particular database.

For example:

IF OBJECT_ID('tempdb..keys','U') IS NOT NULL
DROP TABLE keys
CREATE TABLE keys.[@sourceserver],[@database]. (RowId INT PRIMARY KEY IDENTITY(1, 1),
ForeignKeyConstraintName NVARCHAR(200),
ForeignKeyConstraintTableSchema NVARCHAR(200),
ForeignKeyConstraintTableName NVARCHAR(200),
ForeignKeyConstraintColumnName NVARCHAR(200)

View 2 Replies View Related

Creating A Table And Adding Rows To Database In Studio Management

Aug 12, 2015

I am trying to use the following Query to create the table Agents and add rows to it.

USE REMAXCLASSIC;
IF OBJECT_ID ('dbo.Agents', 'U') IS NOT NULL
DROP TABLE Agents;
GO
CREATE TABLE Agents

[Code] ....

I get the following error messages:

Msg 102, Level 15, State 1, Line 34 Incorrect syntax near '0.25'
Msg 105, Level 15 mark after the character string ');

View 2 Replies View Related

Transact SQL :: Query To Check Properties On A Table When Creating Database?

May 20, 2015

I'm wondering if there is some sql I can run to check properties on a table. This would be used to verify things like data types, allow nulls and default values have been set to avoid mistakes. This could be done manually one table and one column at a time, but it would be a lot easier to look at it in the results window.

View 5 Replies View Related

Add Multiple Columns In One Shot

Oct 18, 2002

I have a table and want to add 20 more columns to it. I'd like to name these newly added columns such as fname1,fname2....
I don't want to type them mannully. I tried to use loop. But when I use "alter table add" in the loop, I couldn't find a way to substitute the column name in the loop.
Is there any other good solution to this?
Thanks

View 3 Replies View Related

Add Multiple Columns In One Shot

Oct 18, 2002

I have a table and want to add 20 more columns to it. I'd like to name these newly added columns such as fname1,fname2....
I don't want to type them mannully. I tried to use loop. But when I use "alter table add" in the loop, I couldn't find a way to substitute the column name in the loop.
Is there any other good solution to this?
Thanks

View 1 Replies View Related

Add Multiple Columns In One Shot

Oct 18, 2002

I have a table and want to add 20 more columns to it. I'd like to name these newly added columns such as fname1,fname2....
I don't want to type them mannully. I tried to use loop. But when I use "alter table add" in the loop, I couldn't find a way to substitute the column name in the loop.
Is there any other good solution to this?
Thanks

View 3 Replies View Related

SYBASE, I Know It Is Not SQL Server But This Is A Long Shot

Oct 1, 2001

To anyone who knows how to use sybase. One of our guys has put in a sybase system and not told the rest of us about it and know their is a problem and it is in my lap. Surprise, surprise.
Just asking does antyone know how to rebuild a sybase database after it has been recovered from previous data and is now twice the size that it was origonally. Please help if any one can>

Many thanks to any one who can help.

View 1 Replies View Related

Modify All Store Proc In DB In One Shot

May 19, 2004

Is it possible that i can use a store proc to modify all the rest of my store procedures that i have in my DB ??

I have so many created allready and it will be to long to go throught each one of them to modify my text inside.

what i wish to do is a store proc that will allow me to loop to all my store proc of the current DB and look inside for specific text that i would like to change with the new value !!

any advise or example..

thanx.

View 4 Replies View Related

How Do I Implement Snap Shot Replication..?

Jan 11, 2008



how do i implement Snap shot replication..?
(IN SQL EXPRESS SERVER)
thanks.

View 1 Replies View Related

Integration Services :: Multi Files In One Shot

Jul 21, 2015

i have multiple folders in a directory and each folder contains multiple files of same extension but with different formats(columns) and names(xmp: file aand file b). We have a data task in which we are joining(merge) both files and loading into table..should i use foreach, but then it takes 1 file at a time and i need the other file also to join it in data flow.

View 4 Replies View Related

Problem With Merge Replication--with Snap Shot Agent

Sep 20, 2004

i am having a problem with the merge replication.
has over 400 thousand records and is running on a hp server with a raid 5 configuration.
i am trying to create a merge replication on another server with the same configuration.

i am facing problems in 2 places.

firstly i created a push subscription and ran the snap shot agnt.
but the snap shot agent times out and expires .. as a result of which i am not able to create the initial snap shot on the subscribers end.

next i thought i would manualy create a snap shot
and so i backed up the dabase from the publisher and restores it on the subscription side.

now i tried to create a new subscription by chosing the option... the dabase alredy conists of the data base and schema
and i get a n error saying
"SQL Server Enterprise Manager encountered errors creating push subscriptions for the following Subscribers:

ICE: Error 20086: Publication '%s' does not support the nosync type because it contains a table that does not have a rowguidcol column

what do i do to solve this problem....
please try and give me a solution to solve either ways.

thanks,

--ggupta

View 9 Replies View Related

Creating Trigger On Creating Table

Jan 28, 2008



Hi,

If I want to automatically insert a record which has default value in a table,
how can I create the trigger?

View 5 Replies View Related

Difference In Creating Temporary Table By #table And ##table

Nov 29, 2006

Banti writes "IF i create temporary table by using #table and ##table then what is the difference. i found no difference.
pls reply.
first:
create table ##temp
(
name varchar(25),
roll int
)
insert into ##temp values('banti',1)
select * from ##temp
second:
create table #temp
(
name varchar(25),
roll int
)
insert into #temp values('banti',1)
select * from #temp

both works fine , then what is the difference
waiting for ur reply
Banti"

View 1 Replies View Related

Creating A Common Table Expression--temporary Table--using TSQL???

Jul 23, 2005

Using SQL against a DB2 table the 'with' key word is used todynamically create a temporary table with an SQL statement that isretained for the duration of that SQL statement.What is the equivalent to the SQL 'with' using TSQL? If there is notone, what is the TSQL solution to creating a temporary table that isassociated with an SQL statement? Examples would be appreciated.Thank you!!

View 11 Replies View Related

Creating A Table Column That Only Takes Data From Another Table.

May 20, 2006

I am trying to create a table that holds info about a user; with the usual columns for firstName, lastName, etc....  no problem creating the table or it's columns, but how can I "restrict" the values of my State column in the 'users' table so that it only accepts values from the 'states' table?

View 2 Replies View Related

Creating Database From Stored Proc With Variable Holding The Database Name

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

Guidelines For Creating A Database Snapshot On A Mirror Database

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

Snap Shot Agent Refuses To Snap New Articles.

Sep 7, 2005

Hi There

View 4 Replies View Related

Transferring Objects Form Schema A To Schema B In One Shot....!

May 27, 2008

I have 35+ tables and 15+ stored procedures with SchemaA, now I want to transfer them to SchemaB.

I know how to do one by one...!

alter schema SchemaB transfer
SchemaA.TableA

but it will take long time...!

Thanks,

View 3 Replies View Related

Creating Table Fields Dynamically From Another Table Row

Aug 31, 2006

Hello all:

Is it possible to creates fields of the table dynamically?. I have this situation in my project. This is just a small sample. I have row of length 140. I don't wan't to declare all this fields manually using the create table command.

The description of table is as, in this table all the field are of type varchar only, there are like 140 columns.

create dummy emp (
field1 VARCHAR(100), field2 varchar(200), field3 VARCHAR(100).... )

Table: Dummy
================================================== ==
field1 field2 field3..........
Empid Empname empaage1 sam 23...........
2 rai 22............
.
.
.
n raj 45.............
================================================== ==
Now I want to create another table as "EMP" , with proper data type
fields too..

create table emp (
empid int, empname varchar(100), empage int....)

The table should look like as:

Table: EMP
================================================== ==
Empid Empname empaage............
1 sam 23...............
2 rai 22................
.
.
.
n raj 45.................
================================================== ==

I want to do this dynamically.....
Some how I need to extract those field from table[dummy]; the first row acts as a column header for the table[Emp] and the subsequent row acts as a record for the table[Emp]

A small rough snippet of the code will be appreciated....

Waiting for replies........
saby

View 1 Replies View Related

Creating A Table And Dropping That Table At End Of Execution

Mar 19, 2012

I am using a Stored procedure in which I am creating a table and dropping that table at the end of execution. This SP is calling every 10 second (but no concurrent access) from my application. Is there any issue using the drop table command in the SP? will it create any memory fragmentation issue in SQL server?

View 7 Replies View Related

Creating A Stored Procedure That Will Summarize Data In A Table Into A Table Reflecting Period Data Using An Array Type Field

Sep 20, 2007

I am attempting to create a stored procedure that will launch at report runtime to summarize data in a table into a table that will reflect period data using an array type field. I know how to execute one line but I am not sure how to run the script so that it not only summarizes the data below but also creates and drops the table.

Any help would be greatly appreciated.

Current Table

Project | Task | Category | Fiscal Year | Fiscal Month | Total Hours
---------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 2007 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2007 | 02 | 20
Proj 1 | Task 1 | Cat 3 | 2007 | 03 | 35
Proj 1 | Task 1 | Cat 1 | 2008 | 01 | 40
Proj 1 | Task 1 | Cat 2 | 2008 | 02 | 40
Proj 1 | Task 1 | Cat 3 | 2008 | 03 | 40

Proposed Table

Project | Task | Category | Fiscal Month 01 | Fiscal Month 02 | Fiscal Month 03 | Fiscal Year
---------------------------------------------------------------------------------------------------------------------------------------------------
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2007
Proj 1 | Task 1 | Cat 2 | 0 | 20 | 0 | 2007Proj 1 | Task 1 | Cat 3 | 0 | 0 | 35 | 2007
Proj 1 | Task 1 | Cat 1 | 40 | 0 | 0 | 2008

Proj 1 | Task 1 | Cat 2 | 0 | 40 | 0 | 2008
Proj 1 | Task 1 | Cat 3 | 0 | 0 | 40 | 2008

Thanks,
Mike Misera

View 6 Replies View Related

Creating A Dimension Table From A 3-key Table

Jan 13, 2005

Hi All,

I have a situation with a table that was created for a transactional

system with a 3 columns key. The table is similar to the following:

countrystatecitydescription
11221City A from country 1 and state 12
11321City A from country 1 and state 13
21422City B from country 2 and state 14
21522City B from country 2 and state 15


Now I'm trying to create a dts package that would allow me to build a

city dimension table with unique codes (keys) for each city. What kind of

transformation should I use to translate the old codes (based on the

country-state-city key) into the new ones and preserving the data

integrity?

Thanks,

Ignacio

View 2 Replies View Related

Creating New Table From Existing Table

Apr 20, 2006

Hi,

I m new to this forum with a Query

Create table <table name1 > as select * from <table name2>

this works for oracle. do anybody knows its alternative in sqlserver 2000

thanx. :)

View 4 Replies View Related

Creating Table

Jan 15, 2008

I'm trying to create programmatically a table in my db on sql server 2005.1. I created a string "CREATE TABLE ....." and then tried to execute it using my ADO. That didn't work, so I copied the string into  a query in sql server and got the message "CREATE TABLE sql is not supported". Why's that? 2. I created a stored procedure in my db that will get the "CREATE TABLE...." string and execute it.   I thought it would look something like this:    parameter @createString varchar(MAX)    BEGIN                                                            BEGIN       EXEC @createString           or                             @createString     END                                                                END    Both these options didn't work.How can I make it work properly?Thanks.  

View 3 Replies View Related

Creating A Table

Dec 22, 2003

I need a module to help me create a SQLServer database table. Is there a module that allows users to specify parameters in the creation of a SQLserver table?

View 1 Replies View Related

Creating A Table

May 1, 2000

Hello, folks.

I wonder whether I can create a table based on the script in SQL Analyzer.

If this is possible, can you folks tell me how to do it.

Thanks in advance.

Hyunhyo Jun
GIS Research Group
University of Colorado

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved