Showing posts with label extract. Show all posts
Showing posts with label extract. Show all posts

Wednesday, March 28, 2012

HOw to Saving data from SQL server

Hi

I have only read ( select access) in a sql server database(2000). I am able to scripts the database.

Can any ony have any idea how to extract the data from database?

not the backup of db, i don't have the access.

No DTS to extract data into text file.

some thing like save the table with data?

I have more than 300 tables.

Thanks

sandipan

I think you don't have many options here. If you only have select permission; the only option I see is to export the data via Select...from... You could script a create table and then load it into a new DB where you, perhaps have rights to create a backup.

You could do all that using SSIS.

sql

Wednesday, March 7, 2012

How to retrieve primary key columns from db?

Hello all. I need to extract the column names that form the primary key group on a table in SQL Server. I have a table called Account and it contains ten columns. The primary key consists of two columns - MasterAccountID, AccountID. This primary key is a unique constraint and is clustered (it acts as an index as well as a primary key group). I have tried the following to no avail:

exec sp_pkeys Account -> returns no rows

exec sp_helpindex Account -> throws an error stating that the object 'Account' does not exist

If I run the following SQL statement, I can see all of the PK_* constraints in the database, so I know they are there:

select * from information_schema.table_constraints
where constraInt_type IN ('PRIMARY KEY','FOREIGN KEY')


Again, I need to be able to specify a table name and have it return the columns (don't care if it returns extra fields) that make up the primary key fields for that table. Thanks!


Perhaps something like this:

select

*fromsyscolumnswhere id=object_id('yourTable')and colidin(select colidfromsysindexkeyswhere id=object_id('yourTable'))

|||

declare

@.TableNamevarchar(255)

set

@.TableName='tblPersons'

SELECT

CCU.*

FROM

INFORMATION_SCHEMA.Table_Constraints TCJOININFORMATION_SCHEMA.Constraint_Column_Usage CCUON CCU.CONSTRAINT_NAME= TC.CONSTRAINT_NAME

WHERE

CONSTRAINT_TYPE

='PRIMARY KEY'AND TC.TABLE_NAME= @.TableName

but this also works: look at the quotes ''

execsp_pkeys'tblPersons'