|
Hi
does any1 know how to copy sql database.
I need to make another version of the database for test purposes
thanks
|
|
|
|
|
Take a backup and restore it to a new database...
You can do this form SQL Server Management Studio For MS SQL Server/MS SQL Server Express, from Enterprise Manager for MS SQL Server 2000 and 7.0.
From Query Analyzer, SQLCMD or other sql tools; lookup BACKUP (T-SQL) and RESTORE (T-SQL) in books online or Google.
|
|
|
|
|
Hi,
Open Sql Server 2000 Enterprise Manager Select Your DataBase Right Click on that there is an option Under All Tasks->BackUp DataBase->In Destination Path Give The Location Where u want to store that database back up.
After that Click Ok.
Then Restore this database backup where ever you want.
For that Just create one database Right Click on that Select
All Tasks->Select Restore Database,Select From Device It will ask the
location there u specify ur DataBase Backup Name Click Ok.
Regard's
Veeresh
i want to join this group
|
|
|
|
|
Hi,
Open Sql Server 2000 Enterprise Manager Select Your data base Right Click on that there is an option Under All Tasks->BackUp data base->In Destination Path Give The Location Where u want to store that database back up.
After that Click Ok.
Then Restore this database backup where ever you want.
For that Just create one database Right Click on that Select
All Tasks->Select Restore Database,Select From Device It will ask the
location there u specify ur DataBase Backup Name Click Ok.
Regard's
Veeresh
i want to join this group
|
|
|
|
|
Hi
SQL Profiler for Sybase?
Thanks!
devy
|
|
|
|
|
How do I enumerate tables in a given database? I remember you need to open a cursor to a system table...?
Thanks
devy
|
|
|
|
|
|
I created a very simple app to better understand LINQ and WPF, I'm using the Northwind db and the table Employee. In the code behind for the window in the constructor I have the following code.
public Window1()
{
InitializeComponent();
dc = new NorthWindDataContext();
this.DataContext = dc.Employees;
}
In the XAML file a have a combobox that lists each record in the table, there are also four Textbox fields, a New and a Save button, the app runs OK, I can make changes to existing records OK, but I don't understand how to add new records. I would like to be able to click the New button, the textboxes clear allowing me to enter new data, I click the Save button and the record is written to the db.
How would I do this ?
|
|
|
|
|
Hi,
I have a two medium sized tables, one containing 2.000.000 cities, and one containing localized names for part of these cities in sofar 3 languages ( about 3.000.000 records)
When users look for a city the following query is basically being used:
SELECT TOP 10 COALESCE(Cities_Localized.[Name], Cities.[Name])
FROM Cities
LEFT JOIN Cities_Localized ON Cities.CityID = Cities_Localized.CityID AND
Cities_Localized.Language = 'en-US'
WHERE Cities.[Name] LIKE 'T%' OR --where T is the first letter of some city
Cities_Localized.[Name] LIKE 'T%'
ORDER BY COALESCE(Cities_Localized.[Name], Cities.[Name])
This is of course an abstracted version, but it deals with the basic problem. This query takes a long time. Especially the sorting. Does anyone have a few tips on how to make this query faster?
Thanks,
Gidon
|
|
|
|
|
COALESCE is built to handle numerous elements. You are only using two so ISNULL(Cities_Localized.[Name], Cities.[Name]) might be a bit faster (maybe not?).
I assume you already have an index on [Name] in both tables to handle the LIKE comparisons.
The next thing I would try is a temporary table so that the NULL testing is only done once. I am assuming you are using SQL server.
DECLARE @tmp TABLE
(
CityName NVARCHAR(200)
)
INSERT INTO @tmp (CityName)
SELECT TOP 10
ISNULL(Cities_Localized.[Name], Cities.[Name])
FROM
Cities
LEFT JOIN
Cities_Localized
ON (Cities.CityID = Cities_Localized.CityID) AND
(Cities_Localized.Language = 'en-US')
WHERE
Cities.[Name] LIKE 'T%' OR
Cities_Localized.[Name] LIKE 'T%'
SELECT
CityName
FROM
@tmp
ORDER BY
CityName
You can also try a UNION query and see if it is any faster.
SELECT
[Name] AS CityName
FROM
Cities
WHERE
[Name] LIKE 'T%'
UNION
SELECT
[Name]
FROM
Cities_Localized
WHERE
Cities_Localized.Language = 'en-US' AND
Cities_Localized.[Name] LIKE 'T%'
ORDER BY
CityName
If none of those resulted in a fast enough query, I would develop a table that contained all city names (normal and localized) with a Foreign Key back to the City table.
|
|
|
|
|
Hi Michael,
Thanks for your answer, I tried all of your queries, and here are the results:
- ISNULL vs COALESCE - no measurable difference
- Temp table solution. Worked fast, but the problem is the temp table is filled with 10 records starting with a T, but they can be Tabasco, but also Tu.... The ORDER BY is perfromed on this 'random' choosen top 10 cities that start with a T. So it doesn't work. The order has to be performed on the main SELECT query anyway.
- UNION solution - worked very very fast. Made me very happy, but misses a feature of the join, namely: when the city Paris is translated to Dutch as Parijs (note the extra J), both records will show up by with a search of LIKE 'Pari%', while I want that when a record is translated, only the translated record should show up (the join takes care of that in the original select).
I hope you can help me with the pitfalls in the solutions, because they do have a clear speed advantage.
Otherwise i will just have to go for the last solution. "develop a table that contained all city names (normal and localized) with a Foreign Key back to the City table"
|
|
|
|
|
Try
--Get top 10 city names that do NOT have a localised version.
select top 10 C.CityId, C.Name
into #tmp
from Cities C
left outer join Cities_Localization CL
on CL.CityID = C.CityID
and CL.Language = 'en-US'
where C.Name like 'T%'
and CL.CityID is null
order by C.Name
--Add the top 10 localised city names.
insert into #tmp (CityID, Name)
select top 10 CL.CityID, CL.Name
from Cities_Localization CL
where CL.Name like 'T%'
and CL.Language = 'en-US'
order by CL.Name
--Return top 10 cities (localised or not).
select top 10 #tmp.Name
from #tmp
order by Name For the best performance, you probably need the following indexes in place:
Table: Cities
Non-clustered index on Name, CityID (to make name-search as fast as possible).
Table: Cities_Localization
Clustered index on CityID, Language (to make checking for localised versions as fast as possible).
Non-clustered index on Name (to make searching for localised names as fast as possible).
Hope this helps.
Andy
|
|
|
|
|
Very nice, very fast. Just one more question, as i said in my initial post, the query was just an abstraction of the bigger whole.
Now in the bigger whole, i don't select the top 10, but i do paging (using SQL 2005's ROW_NUMBER OVER (ORDER BY LocalizedCityName ASC)
Is there a way - withouth filling the #tmp table with all the records that match 'T%' and then on that add the row number - to use your design and use paging?
|
|
|
|
|
I hate to admit it but I'm having trouble thinking of a tidy way to solve that.
Question: Did my suggested indexes have much of an effect on your original select statement?
My next suggestion would be to maintain a denormalised table (i.e. using triggers) that coalesces the Cities and Cities_Locatization tables together. The performance would be really quick - but its not very subtle.
There may possibly be a way of getting "indexed views" to solve this. I had a quick look, but they don't allow outer joins or union joins - so any solution would be a little bodgy.
Sorry I couldn't be of more help.
Regards
Andy
|
|
|
|
|
I was affraid so. So I guess the solution is putting the Cities and Cities_Loc. together. Well the good thing is that new cities are not being added by users. We have once every while an update from "localizers/dataentry" and after checking we update the production tables. So no need to use triggers.
It's a shame there is no subtle solution...
Thanks for your help.
Gidon
|
|
|
|
|
Have you considered using a textbox to input part of the name then Ajax to dynamically pull matching names from the database?
|
|
|
|
|
That comment made me think. Because that's exactly the purpose of the stored procedure.
But I designed the stored procedure in such a generic way that i can also use it for datasets where paging has to be used. (input of the sproc is : CityName, PageIndex, PageSize, TotalRecords OUTPUT)
But actually it will mostly be used by the Ajax thing, so than i don't need paging (it always returns the top x records from page 1), and can use your fast solution.
If page 2 is wanted, i use the slower solution i have right now.
Thanks for that comment!!!
|
|
|
|
|
I need the syntax of using Stored Procedure in several cases Using C# code. and also how to create table using stored procedure in SQL server
I perform below systax in my project but I want to replace them using Stored procedure in C#.
DELETE
SqlCommand cmd=new SqlCommand("delete from logininfo where uid='"+user_id.Text+"'",con);
cmd.ExecuteNonQuery();
UPDATE
SqlCommand cmd2=new SqlCommand("update logininfo set pwd ='"+ newpwd.Text) +"' where uid='"+user1+"'",con); cmd2.ExecuteNonQuery();
SELECT
SqlCommand cmd=new SqlCommand("select b from logininfo where uid='"+user+"'",con);
INSERT
SqlCommand cmd=new SqlCommand("insert into vendor_master values('"+ name.Text +"')",con);
cmd.ExecuteNonQuery();
|
|
|
|
|
This is the code that creates the stored procedure
CREATE PROCEDURE DeleteUser
@userId int
AS
DELETE FROM LoginInfo WHERE uid = @UserId;
GO
Here is the snipped that calls the stored procedure from C#
int userId = int.Parse(user_id.Text);
SqlCommand cmd = new SqlCommand("DeleteUser");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = myConnection;
cmd.Parameters.AddWithValue("@UserId", userId);
cmd.ExecuteNonQuery();
You should, hopefully, be able to figure the rest out from this example.
|
|
|
|
|
Yes ,I think i can do the rest.
Thank u very much.
|
|
|
|
|
Hello,
is there a way on how to insert a new row into an MS SQL table that only contains an autogenerated primary key column?
Thanks,
Michal
|
|
|
|
|
What are you inserting into the row? You might want to reconsider the design of only having one column and it being auto.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Paul,
thanks for the reply.
It's exactly what my design is. There's just one column and it is being autogenerated.
Let's say this table is named Table_A. The sole auto int PK column in Table_A is named Table_A_Id.
Let's say there's another table, Table_B. This Table_B contains, among other things, a column named Table_A_Id. There is a foreign key relationship between Table_A.Table_A_Id and Table_B.Table_A_Id. By way of this FK relationship, the unique Table_A.Table_A_Id rows are being linked to many Table_B.Table_A.Id rows.
Each time I insert a new row into Table_A, I get the last autogenerated PK by issuing SELECT @@IDENTITY. I take this last PK from Table_A and insert multiple rows to Table_B that link to this Table_A.Table_A_Id.
The problem is that if Table_A only contains one autogenerated PK column, there's actually nothing to insert (no columns, no values) into Table_A. My current workaround is that I've added a text column named Comment to Table_A. I'm generating a new row in Table_A by issuing INSERT INTO Table_A (Comment) VALUES ('') then.
But I'd like to find out how to generate a new row in Table_A with no workarounds.
Thanks much,
Michal
|
|
|
|
|
Why on earth do you want a table with only an autogenerated column on it? That's just begging for somebody to point out that you've failed the database normalisation test here. Plus, don't use @@IDENTITY to get the identity of a column. Use SCOPE_IDENTITY() instead.
|
|
|
|
|
Pete O'Hanlon wrote: Why on earth do you want a table with only an autogenerated column on it?
He explained it to me in his reply to my post. But he still makes no sense and yes, he really blew the database normalization here.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|