Showing posts with label alter. Show all posts
Showing posts with label alter. Show all posts

Friday, March 30, 2012

How to rename a database?

hi

every time I try to rename my database I face an error

I want to rename the database file phisically not just changing logigal name with

Alter Database <database name> modify name command

please step by step tell me what to do

whether with using TSql or Managment Studio

thanks

detach the database

rename the files

then "attach as" new database name

sql

How to rename a database?

hi

every time I try to rename my database I face an error

I want to rename the database file phisically not just changing logigal name with

Alter Database <database name> modify name command

please step by step tell me what to do

whether with TSql or Managment Studio

thanks

Workaround.

1. Deattach database files.
2. Rename physical files.
3. Attaching database files again and specify names you want.

you can do all this from SQL Management Studio 2005.

- Jignesh Desai

|||

Best way to do bit Your problem:

Use command:

sp_renamedb <old_name>, <new_name>

That's all. ;)

Monday, March 26, 2012

How to remove a file [dbcc shrinkfile(filename,empty) is not working]

I tried to remove a file from a filegroup by using the following two comamnd
1) dbcc SHRINKFILE('FileName1', EMPTYFILE)
2) ALTER DATABASE PED_PROD REMOVE FILE FileName1

but I am getting the following error message

Server: Msg 5042, Level 16, State 1, Line 1
The file ''FileName1'' cannot be removed because it is not empty.

Please help in this

Thanks in Advance,
SateeshHowdy

What version of SQL are you using?

Cheers

SG

Friday, March 23, 2012

How to regenerate a stored proc (drop & create or alter procedure) ??

Hi all.
Cf my other news: How to change or alter a user defined data type?
I need to regenerate (not only "sp_recompile") a list of stored procedures.
With the "SQL Server Enterprise Manager" it's very easy: just open each
Stored proc and save it. But how to do that by transact SQL script '
Thanks.
Lilian.What purpose does "regenerating" these serve? There are 2 ways to do this
depending on what your after. One way is to use the DROP PROCEDURE xxx
command and then issue the CREATE PROCEDURE xxx ... command. The other is
to use the ALTER PROCEDURE xxx.... command. Drop will not keep any
existing permissions and ALTER will.
--
Andrew J. Kelly
SQL Server MVP
"Lilian Pigallio" <lpigallio@.nospam.com> wrote in message
news:u7Os%23CHQDHA.2228@.tk2msftngp13.phx.gbl...
> Hi all.
> Cf my other news: How to change or alter a user defined data type?
> I need to regenerate (not only "sp_recompile") a list of stored
procedures.
> With the "SQL Server Enterprise Manager" it's very easy: just open each
> Stored proc and save it. But how to do that by transact SQL script '
> Thanks.
>
> Lilian.
>sql

How to reference the primary key of a newly added record in trigger?

Please help me somebody solve my problem with my first :o trigger:

ALTER TRIGGER partner_update
ON dbo.partner
FOR UPDATE
AS
INSERT INTO partner (name) SELECT name FROM deleted
UPDATE invoice SET id_partner= *** WHERE id_partner = (SELECT id_partner FROM deleted)


*** - here I want to add a "reference" to the newly added record's automatically generated primary key (not to the updated!) Is it possible?I'd use:ALTER TRIGGER partner_update
ON dbo.partner
FOR UPDATE
AS
BEGIN
INSERT INTO partner (name)
SELECT name FROM deleted

UPDATE o
SET id_partner= i.id_partner
FROM dbo.invoice AS o
INNER JOIN deleted AS d
ON (d.id_partner = o.id_partner)
LEFT OUTER JOIN inserted AS i
ON (i.id_partner = o.id_partner)
ENDThis trigger takes a rather perverse view of the universe, allowing for the possiblity that some low-down, high-smelling, bundle-of-dung might possibly change the value of the id_partner column. The invoice table might or might not like that, since the trigger would then NULL out the invoice.id_partner column!

-PatP