This question already has answers here:
Changing the name of a SQL database
(4 answers)
Closed 1 year ago.
I want to change database name from Test to NewTest
Alter Database Test Set NewTest
But it does not working
The correct syntax is:
ALTER DATABASE Test MODIFY NAME = NewTest;
Check if the account you are using has the correct privileges.
Related
This question already has answers here:
How do I get list of all tables in a database using TSQL?
(20 answers)
Closed 6 years ago.
I am using SQL Server 2014 and want to get all the tables name in a particular database STUDENT through a SQL query.
How is it possible?
Thanks
You want to query sys.objects and look for everything with the type description 'USER_TABLE'. You could use a query like this;
SELECT
*
FROM STUDENT.sys.objects
WHERE type_desc = 'USER_TABLE'
The FROM clause has the usual format: DatabaseName.SchemaName.TableName.
Or as marc_s mentions, you can use sys.tables instead;
SELECT
*
FROM STUDENT.sys.tables
This question already has answers here:
Upserting in MS-access
(6 answers)
Closed 7 years ago.
I want to check whether a row exists or not before inserting a new one in Access 2007.
I have the following working query in SQL Server but I'm having trouble converting it to Access.
update category set name='hell' where categoryid=287
if ##rowcount=0
begin
insert into category(categoryid,name,path,parentcategoryid,creationdate) values (287,'a','a',12,'')
end
Try this
update category set name='hell' where categoryid=287;
if not exists(select * from Category where categoryid=287)
insert into category(categoryid,name,path,parentcategoryid,creationdate)
values (287,'a','a',12,'');
This question already has answers here:
How do I ignore ampersands in a SQL script running from SQL Plus?
(7 answers)
Closed 7 years ago.
One of my oracle database columns needs to have the value 'user.password&user.user_name'
When I execute the query, I see a popup, because the query has '&user' in it. How do I get around it?
Example query:
update Table A set value = 'user.password&user.user_name' where id = 1;
Modify the query to insert the value
'user.password'||chr(38)||'user.user_name'
Example query:
update Table A set value = 'user.password'||chr(38)||'user.user_name' where id = 1;
You can find several decisions at How do I ignore ampersands in a SQL script running from SQL Plus?
Btw, you can use just update table set value = &value where id = 1 and type your value into popup.
chr(38) should work independent of the platform.
However, if you are using SQL*Plus, then you could use the sqlplus command:
set define off
In SQL*Plus, ampersand is used for substitution variable. The above command will ignore it.
For example,
SQL> SET DEFINE OFF
SQL> SELECT 'user.password&user.user_name' FROM DUAL;
'USER.PASSWORD&USER.USER_NAM
----------------------------
user.password&user.user_name
SQL>
Well, of course,chr(38) will work too:
SQL> SELECT 'user.password'||chr(38)||'user.user_name' FROM dual;
'USER.PASSWORD'||CHR(38)||'U
----------------------------
user.password&user.user_name
SQL>
This question already has answers here:
How to replace a string in a SQL Server Table Column
(10 answers)
Closed 8 years ago.
i have table,
id Name
1 aaaaAAbbbb
2 bbbbAAaaaa
3 aabbAAbbaa
This is my table,i want to update 'AA' with 'BB' using sql server 2008
update myTable set [Name] = REPLACE([Name], 'AA', 'BB')
REPLACE applies to SQL Server 2008 upwards.
You can use
REPLACE(Name,'AA','BB');
and update you column.
This question already has answers here:
getting all chars before space in SQL SERVER
(2 answers)
Closed 8 years ago.
I want to extract a certain part of a row. if there is something like this ..." abcd - productA", " zas1234 - productC", how do I extract everything before the dash(-)?
I tried a left(column name,'-') it didnt work. I am on SQL Server 2012.
The column from which I am trying to extract is a varchar column.
It would be great if someone could help me.
Try this,
select SUBSTRING(column_name, 1, CHARINDEX('-', column_name)-1) from table_name;
DECLARE #varStr VARCHAR(MAX)
SET #varStr='abcd - productA'
SELECT CHARINDEX('-',#varStr)
SELECT LEFT(#varStr,CHARINDEX('-',#varStr)-1)