Showing posts with label creates. Show all posts
Showing posts with label creates. Show all posts

Thursday, March 29, 2012

Dropping tempe tables

My query creates a new temp table every time a report is run. I need to check
if the table exists before I drop it and perform a select into. Since SQL
Server appends an ID (session ID?) to the temp table name, I am unable to
drop the table prior to running the query. Is there a better way to handle
this? Any help would be appreciated.Try this. make sure the temp table does not exist, and you can do it this way.
Drop your new table at the end if your query.
CREATE PROCEDURE [dbo].[Test] AS
Select top 5 * into #temp from Orders
Select * from #temp
Drop Table #temp
GO
"DrM" wrote:
> My query creates a new temp table every time a report is run. I need to check
> if the table exists before I drop it and perform a select into. Since SQL
> Server appends an ID (session ID?) to the temp table name, I am unable to
> drop the table prior to running the query. Is there a better way to handle
> this? Any help would be appreciated.

Wednesday, March 21, 2012

Drop The Create Table

I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
Either add an ExecSQL task to add the permissions or do the create AND the
GRANT both within the same ExecSQL task.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
..
"Darren" <jobs@.supre.au.com> wrote in message
news:%23lUe7vvDFHA.960@.TK2MSFTNGP09.phx.gbl...
I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

Drop The Create Table

I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Either add an ExecSQL task to add the permissions or do the create AND the
GRANT both within the same ExecSQL task.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"Darren" <jobs@.supre.au.com> wrote in message
news:%23lUe7vvDFHA.960@.TK2MSFTNGP09.phx.gbl...
I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!sql

Drop The Create Table

I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!Either add an ExecSQL task to add the permissions or do the create AND the
GRANT both within the same ExecSQL task.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com
.
"Darren" <jobs@.supre.au.com> wrote in message
news:%23lUe7vvDFHA.960@.TK2MSFTNGP09.phx.gbl...
I have a DTS package which drops then creates a table before inserting
data from a csv.
My problem is each time I drop the create the table, I must reset the
permissions to the table. How can I automate this?
My current create table code is:
CREATE TABLE [DataFlex].[dbo].[stylemaster] (
[style] varchar (12) NOT NULL,
[retail] numeric (11,2) NULL,
[nzretail] numeric (10,2) NULL,
[descr] varchar (40) NOT NULL,
[colour] int NOT NULL,
[colourway] int NULL,
[season] varchar (10) NULL,
[maingroup] varchar (10) NULL,
[subgroup] varchar (9) NULL,
[story] varchar (9) NULL,
[ac7] varchar (1) NULL,
[fabric] varchar (12) NULL,
[imagename] varchar (30) NULL,
[units] int NULL,
[dollarmargin] numeric (10,2) NULL,
[onsale] char (1) NULL,
[active] varchar (1) NULL,
[fabgroup] varchar (9) NULL
)
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

Monday, March 19, 2012

drop or delete view

hello,

im creating a sp that creates a view from a query then bcp to csv file.

my problem is that when i start the sp, it complains the sp already exists....yes it does, however, i don't if im going about this the wrong way...but i tried the following to no avail

DROP IF EXISTS v_participantTrades

now, does that syntax not work for views?

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'v_participantTrades'))

DROP VIEW v_participantTrades

|||

aah that explains the whole, create view needs to be the first statement!

thank you

|||

exuse my incompetence however,

Invalid Object name 'sys.views'.

blaaa was my ineptitude - sysobjects for my version

cheers

Friday, March 9, 2012

DROP DATABASE problem

I have an application (VS2005, C#) that creates one or more SQL Server
Express (2005) databases and populates them with a schema and some
initial data. This all works.
From time to time there is a legitimate runtime issue that means I
should remove one of the newly created databases. The problem is that
the DROP DATABASE XXX command, which I execute from a new connection via
an admin login on the master database, fails with the error "Cannot drop
database "XXX" because it is currently in use.".
I have checked with "sp_who" and there are no active connections to the
database, but there are a couple of 'sleeping' connections, which I
presume belong to the connection pool.
If I wait for some period of time, the sleeping connections disappear
and the DROP DATABASE command then succeeds.
What is the simplest mechanism for permitting me to drop the database
without waiting for the connection pool to expire on its own?
-ken
Hi Ken,
ALTER DATABASE SomeDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE SomeDatabase
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||I actually found another method that works as well -- I simply use the
SqlConnection.Clear(specificConnection) to remove the entries from the
pool, and this seems to work.
-ken
Jens wrote:
> Hi Ken,
> ALTER DATABASE SomeDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
> GO
> DROP DATABASE SomeDatabase
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>