sql

Which SQL command can I use to see the structure of a table on SQL Server?

Hi there, I have a table on a SQL Server and I would like to export its structure to send to a colleague. Which SQL command should I issue to get the structure? I don't have access to the SQL Server Management Studio. Thanks ...

easiest way to map ids during database refactoring

i have a number of tables with a column called OrderId. I have just done a refactoring and i want to get rid of the Order table and i have a new table called Transaction. I want all tables that have an OrderId column to now have a TransactionId column This is complete. I now need to populate the transactionId column. I have a mappi...

is count(indexed column) faster than count(*) ?

Possible Duplicate: Performance of COUNT SQL function Hi all, I've very large tables and I need to know number of records in each , My question is does it reduce the run time if I run : select count(indexed column like my PK) from tbTest instead of select count(*) from tbTest ...

Query a union query.

First of all I know this is probably bad sql but I just need to run a few queries of this and it will not go into official use anywhere. I need to find some records from the fcc uls database so I got the tables and they have one table with locations and one with frequencies for a number of categories. So what I've done is run queries to...

Quickest Way to Copy SQL Data

I could use some suggestions / ideas. I wrote a console application that queries all data from a table in MS Access (I know, but I inherited it) to a SQL table. It runs every morning as a scheduled task. The fields between the two tables are not identical. Currently I select all data from the MS Access table, loop through the dataset and...

SQL: using WHERE AND instead of HAVING

here's an example of a SQL statement where we use HAVING: select column1 from table1 where condition1 having condition2; isn't it the same exact thing if we do this: select column1 from table1 where condition1 AND condition2; what is the difference between these two? ...

Statistics on Query Time (PostgreSQL)

I have a table with a billion rows and I would like to determine the average time and standard deviation of time for several queries of the form: select * from mytable where col1 = '36e2ae77-43fa-4efa-aece-cd7b8b669043'; select * from mytable where col1 = '4b58c002-bea4-42c9-8f31-06a499cabc51'; select * from mytable where col1 = 'b97242...

tokenizing a metafield.

I am working with a CMS like system, which has a special field defined for use in its forms. This field works similarly to google suggest, executing an sql query behind the scenes and displaying results. The SQL query I am using selects 3 fields from table1, and concatenates them as a result. What I need to do, is split this new metaf...

Complex SQL Join help!

(For a quick recap please see sections titled , DATA. Can only get results in FIGURE A, and FIGURE B, what I want is DESIRED RESULTS, tried everything posted in the answers section.) All, I have been working hard to start smartly using joins in my application. Boy it took me a while but I think I am getting the hang of this, but I can't...

How to make sure that my SQL code is not a scary mess

SQL seems to be the most neglected language when it comes to formatting nicely and readably... And as SQL statements can be incredibly detailed and complex, it makes it extremely hard to work with. But I find that when I try to format my SQL code in the best way possible I'm sometimes unsure of how to do it. I know the standards for Java...

SQL Server statement Where myfield content giving sub-string

Greetings, I'm looking for a SQL Server statement to retrieve records Where myfield content giving sub-string. Thank you, ...

Join a table to itself with no specfic ID

Join a table to itself with no specfic ID I have a table of customer records which has no ID column, a customer may appear in the table more than once with various of the columns populated. I have managed to build a column INIT_SURNAME which is fully poplated but not unique to a customer. How can I merge the rows for matching customer...

Is there a LINQ equivalent to SQL's "0 rows affected"?

I have a simple LINQ to SQL delete statement and would like to know if there is a way to find out the number of records deleted? Sample code would be appreciated ...

How to write a shell script to compile multiple embedded sql in C files (.sqc)?

Hi, I have written 3 .sqc files i.e. embedded sql in host language C. I need to make a (Unix) shell script to simply compile all 3 sqc files in a row. How can I do that? Right now, I can individually run each .sqc file using a Makefile that basically converts the .sqc file to a c file and then compiles it. Can I make 3 individual Makef...

SQL Search column for each variable in CSV string

I have a variable passed to stored procedure Ex: @keywords = 'val1, val3, val5' And i'm trying to see if column named Title contain any of them in it Ex: Title1 - 'Hello val1' Title2 - 'Hello val3' Title3 - 'Hello val1, val3' Title4 - 'Hello' SO my results should return values Title ------ Hello val1 Hello val3 ...

ms-access - grouping select statement

here's the query: SELECT [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)],Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [CountOf1 0 Preanalytical (Before Testing)] FROM [Lab Occurrence Form] WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]!...

Select items that are the top N results for a related table

Say I have a game where a question is asked, people post responses which are scored, and the top 10 responses win. I have a SQL database that stores all of this information, so I might have tables such as Users, Questions, and Responses. The Responses table has foreign_keys user_id and question_id, and attribute total_score. Obviously, ...

SQL Max parameters

I read here that the maximum number of parameters that can be passed to a Stored Procedure is 2100. I am just curious what kind of system would require a SP with 2100 parameters to be passed, and couldn't one split that into multiple SPs? I thought that maybe an SP that calls multiple SPs would require a lot of params to be passed, I ...

Can SQLite handle 90 million records?

Or should I use a different hammer to fix this problem. I've got a very simple use-case for storing data, effectively a sparse matrix, which I've attempted to store in a SQLite database. I've created a table: create TABLE data ( id1 INTEGER KEY, timet INTEGER KEY, value REAL ) into which I insert a lot of data, (800 elements every 10...

ms-access: query (concat multiple records into one)

here's a glimpse of the original table: Occurrence Number Occurrence Date 1 0 Preanalytical (Before Testing) Cup Type 2 0 Analytical (Testing Phase) 2 0 Area 3 0 Postanalytical ( After Testing) 4 0 Other Practice Code Comments 1477 2/5/2010 1.1 Specimen Mislabeled PURSLEY 1476 2/5/2010 1.1 ...