sql-server

SQL max for previous rows

I have Ticker, Dt, [Open], Volume for the input table Dt is yyyy-mm-dd I want to return every row where ticker = 'IBM' and also returns the Ticker, Dt, [Open], Volume fields and then include a max column for only say for the previous x days. Let's say 3 days for the sake of not posting too much data. But I don't know how to get the ...

Export Data Definition Script from an Oracle Database

I am new at working with oracle, my only experience is in sql server. In SQL server you can right click a table and say export create script. I need that for Oracle, specifically 10g. Is there a way via GUI or sql command that can accomplish this? ...

Can't connect remotely to database on SQL Server 2005

Hey Guys, I am new to managing servers but I have just been given full access to set up an MS SQL Database on win server 2003. I have created a Database successfully and can connect locally (via remote desktop server) Problem is I can't connect to the database from my personal computer (remotely, via ms sql server management studio). I...

MDF file size much larger than actual data

For some reason my MDF file is 154gigs, however, I only loaded 7 gigs worth of data from flat files. Why is the MDF file so much larger than the actual source data? More info: Only a few tables with ~25 million rows. No large varchar fields (biggest is 300, most are less than varchar(50). Not very wide tables < 20 columns. Also, no...

Physical Database and Log File location

Hi Folks, How do I get the Physical Database and Log File location (file system path) of a DB in SQL Server 2005? I used this to get the mdf file: {SELECT [Name], FileName FROM sysdatabases} but need to get the log file as well... Cheers, Conor ...

INSERT - PHP & SQL Server

I don't know what is going on, but it just doesn't want to work. I keep getting this error when I submit my form: Array ( [0] => Array ( [0] => 22001 [SQLSTATE] => 22001 [1] => 8152 [code] => 8152 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]String or binary data would be truncated. [message] => [Microsoft][SQL Serve...

PHP & MS SQL - Foreach Loop?

Hi All, I have a table in my ms sql database and am using PHP. What I am trying to do is: Foreach User in table, get his age and favorite color. And for each entry i want to edit it before it is displayed. For example Each User that is retrieved and displayed on the webpage will be hyperlinked. His/her age will be hyperlinked and the ...

SQL Server 2005 - removing table triggers?

How can I remove all triggers from my tables. I have many tables, but about 20 of them have triggers and I want to remove them all. ...

Cant read .bak files.

I wanted to read .bak files that are the backup files of my ms sql database.Now I am wodering how to read these files using Sql Mngmnt studio. Please help me out .Thanks ...

Synching two table in SQL Server

Hi I have two database servers (2 different machine, but on same network). I have one table in Database_1 and same table in Database_2. Only Table in DB_1 will be updated by user, table in DB_2 will be used by other user for read only. I want to program something which can copy the updated record from table in DB_1 to DB_2. I want to m...

"string or binary data would be truncated" when deleting row

Im using Microsoft SQL Server Management Studio Express to connect to our SQL Server 2005 (think its 2005, its version 9.000 something something). I have a table with one column that saves a lot of text. I have set the column type to text. When i have a row with lots of text in this column i cannot delete it. I get the message "string or...

Is data copied when selecting into a temp table?

Hi Guys, I am wondering, when selecting rows and inserting them into a temp table, is the data actually copied or just referenced? For example: SELECT * INTO #Temp FROM SomeTable If the table is very large, is this going to be a costly operation? From my tests it seems to execute about as fast as a simple SELECT, but I'd like a bet...

Server-side NOLOCK in SQL Server

I know that in the Oracle DB I can configure a flag, that all select queries running on a specific DB can be run as if the NOLOCK hint was added. Is there something similar in SQL Server? ...

TSQL RAND random values

Hi, I need populate with dummy values a table. I need create a random generated value "RANDOM_VALUE" for every single row created. Random value must be a string and its range could be only 'A' or 'B'. The script should be able to list a series of row with value A or B randomly generated Here an example of how should work: ROW RAND...

Restore SQL Server DB direct from another DB

How can I restore a live database without taking its backup first. We can do this from SQL Server Management Studio, but I want to do this with script, which i can run as a scheduled job. Please help. ...

store newsletter in sql server database - best practice?

I'm looking for the best way of making an archive for newsletters to be stored in a SQL Server database. What would be the easiest way to do that? I was thinking I could store the newsletters as pdf:s, but what data type should I use in the database? Anything else I should have in mind? Thankful for help! ...

Projecting simultaneous database queries

I’m after some thoughts on how people go about calculating database load for the purposes of capacity planning. I haven’t put this on Server Fault because the question is related to measuring just the application rather than defining the infrastructure. In this case, it’s someone else’s job to worry about that bit! I’m aware there are a...

Universal system to fil gridview with arbitrary columns from db tables

Is there Web application to build universal queries to db by selecting different columns in db tables, and then automate building queries to fill gridview with returned data? (like Design Query in Editor... in Sql Server Management Studio tool.) if not, what about your advice? which technologies to use? Is it possible to do with EntityF...

SQL Server Create View Index which contains distinct or group by

Hi there, I have a table of address data in my SQL server database. This table is not normalized so it contain many addresses the are repeated. Each unique address can be identified by an Id field (these ids repeat often in the table). So i created a view on the table to extract all the unique addresses, using Select Distinct(AddressId...

IS a MIN(coalesce) across multiple tables possible / the best solution for this query in sql 2005?

Hi, I am looking to pull out the minimum value across three tables and then compare this to the lowest value in a fourth table, where the tables are structure like this: Table 1 (event_id (PK uniqueidentifier),date_created,contact_id) Table 2 (event_id (PK uniqueidentifier),date_created,contact_id) Table 3 (event_id (PK uniqueidentifi...