I want to find all the columns with a name that includes a specific string using PSQL in a Pervasive database. How do I do that?
You can query the X$Field table for your string. Something like:
select file.xf$name, field.xe$name from x$field field
join x$file file on xe$file = xf$id
where xe$name like '%some string%'
This query should work for both original and v2 (long metadata) databases but would only work if you have the DDFs (FILE.DDF, FIELD.DDF, and INDEX.DDF at a minimum) and have a PSQL database setup pointing to the DDFs.
Related
How do I select current database name and all the schema for the database name in SYBASE ASE using a query
tried Select db_name
gives invalid column name
Current database:
select db_name()
By 'schema' I'm assuming you mean a user (in the database) who owns at least one object:
select distinct(user_name(uid)) from sysobjects
NOTE: I'm not sitting in front of an ASE instance at the moment so can't recall, or verify, if the 2nd query could generate a NULL ... should be easy enough to test and add an optional where clause to filter out as needed
Limitations on some software I'm using require me to think outside the box, so can you have a query that automatically returns a "file" with the results in it? I imagine it would be as BLOB or a base 64 encoded string or something similar.
Using Microsoft SQL Server
You can use two methods to achieve this
1. Use SQLcmd
SQLCMD -S SERVERNAME -E -Q "SELECT Col1,Col2,Col3 FROM MyDatabase.dbo.MyTable"
-s "," -o "D:\MyData.csv"
Run this above command in a cmd and achieve the expected result.
2. Use OpenRawset
INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Text;Database=D:\;HDR=YES;FMT=Delimited','SELECT * FROM [FileName.csv]')
SELECT Field1, Field2, Field3 FROM DatabaseName
You need to have the Microsoft.ACE.OLEDB.12.0 provider available. The Jet 4.0 provider will work, too, but it's ancient, so I used this one instead.
limitations:
The .CSV file will have to exist already. If you're using headers (HDR=YES), make sure the first line of the .CSV file is a delimited list of all the fields.
If you can create objects in the target database or another database on the same server, you could use the stored procedures and functions from my answer to this question: SSMS: Automatically save multiple result sets from same SQL script into separate tabs in Excel?
You would just need to exclude the #OutputFileName parameter to force output as a single column, single row varbinary(max).
select * into #systables from sys.tables;
select * into #syscolumns from sys.columns;
select * into #systypes from sys.types;
exec dbo.GetExcelSpreadsheetData
#Worksheets = 'sys.tables/#systables/autofilter|sys.columns/#syscolumns/autofilter|sys.types/#systypes'
drop table #systables;
drop table #syscolumns;
drop table #systypes;
Output (truncated):
ExcelSpreadsheetData
-------------------------------------
0x504B0304140000000800DB78295479400A1
I have to take 198 SQL Tables structures. Normally, I know about SP_HELP and ALT+F1 to get single table structure.
How can i get structure multiple tables? If i provide list of table names, output should be structure(Table name(field name, Data type, Length)) of all those tables.
I have only read access to SQL DB.
And, I am new to SQL.
Environment details:
Client Tool: Microsoft SQL Server Management Studio 2014
I have searched in SO, there are answers for single table. But, that doesn't solve my question.
This query will return a list of all tables and their columns with a lot of details about data_type, size, nullability and so on:
USE YourDatabaseNameHere;
SELECT t.TABLE_TYPE, c.*
FROM INFORMATION_SCHEMA.TABLES t
INNER JOIN INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_SCHEMA=c.TABLE_SCHEMA
AND t.TABLE_NAME=c.TABLE_NAME
WHERE t.TABLE_TYPE = 'BASE TABLE'; --With 'VIEW' you'd find views, or just omit the WHERE...
You can use a simple Excel to connect to the database and read this result into a Sheet.
UPDATE
Did not read, that you can use SSMS. Just paste the query into a new query window and execute it. The result can be copy-pasted into excel...
I suggest to use DB Schema tool, which is used to design the database and understand the existing relational database mapping.
By using SQL Server 2008 R2
This will create a script for you then you will be able to run it on other sql server it will create the same Data Base with all talbes.
Right Click On Data Base Name
Go to Task
Go to Generate
Scripts SQL Server 2008 R2 DataBase Image
Next > Next > Next > SetYourPath Next > Finish
first Pic second Pic 3rd Pic 4th Pic 5th Pic
I have one table named "Staff" in access and also have this table(same name) in SQL 2008.
Both table have thousands of records. I want to merge records from the access table to sql table without affecting the existing records in sql. Normally, I just export using OCBC driver and that works fine if that table doesn't exist in sql server. Please advise. Thanks.
A simple append query from the local access table to the linked sql server table should work just fine in this case.
So, just drop in the first (from) table into the query builder. Then change the query type to append, and you are prompted for the append table name.
From that point on, just drop in the columns you want (do not drop in the PK column, as they need not be used nor transferred in this case).
You can also type in the sql directly in the query builder. Either way, you will wind up with something like:
INSERT INTO dbo_custsql
( ADMINID, Amount, Notes, Status )
SELECT ADMINID, Amount, Notes, Status
FROM custsql1;
This may help: http://www.red-gate.com/products/sql-development/sql-compare/
Or you could write a simple program to read from each data set and do the comparison, adding, updating, and deleting, etc.
I have a large db with many tables and sprocs, and I want to find and see, for example, if there is a table with a name that has "setting" as part of it. I'm not very familiar with SqlServer's System Databases like master, msdb etc., I know there is a way to query one of those dbs to get what I need back, does someone know how to do it?
Thank you,
Ray.
SQL Server also supports the standard information schema views. Probably better to use them, since this query should also work across different database engines if you ever need to do a migration:
SELECT * FROM INFORMATION_SCHEMA.tables where table_name LIKE '%Settings%'
the table you want is sys.objects
SELECT *
FROM sys.objects
The table with the info you seek is called sysobjects. Here's a query for what you describe:
SELECT * FROM sysobjects WHERE xtype = 'U' AND NAME LIKE '%setting%'
(U is the type for user tables)
For Sql Server 2005
SELECT * FROM sys.objects where type in ('U') and name like '%setting%'