473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Suppressing duplicate rows

Hi,

I need to get a list of columns and corresponding datatypes for the
given table name. I am using the query:

select
a.name,
b.type_name
from
syscolumns a,
master.dbo.spt_datatype_info b,
systypes c,
sysobjects d
where
a.xusertype = c.xusertype and
b.ss_dtype = c.xtype and
a.ID = (SELECT OBJECT_ID(<tablename>)) and
a.ID = d.ID and
d.ID = (SELECT OBJECT_ID(<tablename>))

This returns multiple sets of data for each column. This is because
the same column name is repeated in multiple tables in primary
key-foreign key relationships. Is there a way in which I can get only
one row for each column of a table?
Jul 20 '05 #1
2 5197

"Monisha" <mo*****@ggn.hcltech.com> wrote in message
news:91*************************@posting.google.co m...
Hi,

I need to get a list of columns and corresponding datatypes for the
given table name. I am using the query:

select
a.name,
b.type_name
from
syscolumns a,
master.dbo.spt_datatype_info b,
systypes c,
sysobjects d
where
a.xusertype = c.xusertype and
b.ss_dtype = c.xtype and
a.ID = (SELECT OBJECT_ID(<tablename>)) and
a.ID = d.ID and
d.ID = (SELECT OBJECT_ID(<tablename>))

This returns multiple sets of data for each column. This is because
the same column name is repeated in multiple tables in primary
key-foreign key relationships. Is there a way in which I can get only
one row for each column of a table?


Assuming you have SQL7 or greater, then using the INFORMATION_SCHEMA views
is often easier (and they're documented, unlike spt_datatype_info):

use pubs
go

select COLUMN_NAME, DATA_TYPE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'titles'
go

The data type lengths etc are also available through that view, if you need
them.

Simon
Jul 20 '05 #2
Monisha (mo*****@ggn.hcltech.com) writes:
I need to get a list of columns and corresponding datatypes for the
given table name. I am using the query:


Involving the completely undocumented spt tables in a query is not
recommendable.

Here is a query that works with out spt_datatype_info:

select c.name, t.name
from syscolumns c
join systypes t on c.xtype = t.xtype
where c.id = object_id('accountstats')
and t.xusertype <= 255
order by c.colid

I should not that the cut-off value of 255 is not documented, but
something I concluded by inspecting systypes table in a database
that I have.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Steen | last post by:
This is probably a silly question to most of you, but I'm in the process of splitting off years from a large DB to several smaller ones. Some of the existing smaller DBs already have most of the...
2
by: Richard | last post by:
Hi Everyone, I have a table in which their is record which is exactly same. I want to delete all the duplicate keeping ony 1 record in a table. Example Table A Empid currentmonth ...
1
by: Asha | last post by:
greetings, does anyone have any idea how to delete duplicate rows in a dataset gracefully (the fast and easy way)
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
0
by: B.N.Prabhu | last post by:
Hi, I have a DataTable with several rows. Its having 20 Columns. when i click the Insert button then i have to check the Database Rows. Whether these new rows are already available in the...
2
by: Rich | last post by:
Hello, I am just checking if there is a property or technique for displaying or retrieving from a dataTable the top 1 row(s) for rows containing duplicate keys (IDs). I have to pull data from a...
5
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English:...
1
by: rfeio | last post by:
Hi! I have a table with several rows, some of which I need to duplicate. The fields of table1 are field1, field2, field3 and field4. Field1 is automatically incremented, field2 will serve as a...
4
by: ravir81 | last post by:
Hi, I am currently working on excel validation using Perl. I am new to Excel validation but not for Perl. I have a question regarding one of the validation. Could anyone please tell me how to get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.