How can I extract sprocs/tables/functions from a specific schema? - sql-server-2008

I need to extract all the tables, stored procs and functions from an SQL Server 08 db that are under a particular schema. I could filter the displayed items in Management Studio and then do Script As -> Drop/Create for each of them, but I would really like to avoid this as there are quite a few items in the schema.
Is there a way to do this?
Edit:
I've had a look at this question (possible duplicate I just found). I'd rather not use an external tool as suggested, since this is at work and I'd need to get approval to use one. Nor do I want one big Create Database script - I need separate scripts for each table/sproc/function.

select
object_name(obj.object_id),
sch.name,
co.definition
from
sys.objects obj
join sys.schemas sch on sch.schema_id = obj.schema_id
left join sys.sql_modules co on co.object_id = obj.object_id
where
sch.name = 'DBO' --here goes your schema name
--The syscoments table was used back in sql 2000 and you should not use it anymore - but when so it is the sys.syscomments table

Visual Studio 2010 Premium includes database project tooling support that allows you to perform database schema comparisons between databases (where you can filter to only a specified database schema) and extract all the objects (and configuration) in a live database to a VS2010 database project, creating a script per object.
See Working with Database Projects.

Something based on
SELECT [text] FROM [syscomments]

Related

Google Data Studio report using Cloud SQL MySQL allows only one table

I'm using Data Studio to generate a financial report dashboard and I'm connecting it to CloudSQL MySQL, but my problem here is that it only requires me one table to use as a data source, and one table wouldn't help me at all to generate a financial report at all.
Here's the image of the process of selecting a Data Source:
I tried selecting Custom Query, which according to this: https://support.google.com/datastudio/answer/7088031?hl=en
Select the CUSTOM QUERY option to provide a SQL query instead of connecting to a single table. Google Data Studio uses this custom SQL as an inner select statement for each generated query to the database.
But I don't know what query should I write to have all my database tables as data sources in Google Data Studio.
Regarding Custom Queries: Had a look online, and didn't seem to find a sample CUSTOM QUERY specific to Google Data Studio and Google Cloud SQL for MySQL, however, on StackOverflow, there are a couple of posts on BigQuery Custom Queries that involve joins, that may be useful:
Data Studio query error when using Big Query view that joins tables
BigQuery Data Studio Custom Query
An alternative is to create individual Data Sources each linked to a single table and then link multiple Data Sources through the use of Data Blending, where a common Join Key links all the respective Tables.
In addition, if you could elaborate on your exact scenario, it would perhaps help users familiar with SQL to provide a more precise solution:
How are the tables structured?
How are the tables linked?
What code have you currently tried?
I also had quite a few issues with the Custom Query using the Cloud MySQL Connector by Google for Data Studio.
The resolution for me was to not run SELECT * but rather SELECT each column by name. Not sure why it doesn't like SELECT * but hopefully this helps someone else.
Example of a successful query.
Example of successful query with join.

Data dictionary file for database in SQL Server 2008 R2

I need to create a data dictionary that lists all the tables, columns and data types in PDF file format. I use SQL Server 2008 R2. How do I get this information?
I was able to view the schema view as someone suggested with all the information I need, but how to make a PDF file format with that information?
I would recommend using a paid product for what you're looking for, http://www.sqldatadictionary.com/ , http://www.apexsql.com/sql_tools_doc.aspx , or http://www.red-gate.com/products/sql-development/sql-doc/ ..
You can use dataedo if you looking for tool with gui. Has free version. Program semi-automatically generates the database schema and then can export schema to pdf or html format. It worked for me.
Best file result when used MS Access data documenter do it for you. I first used a tool to convert MS SQL db to MS Access db. Then I used data documenter tool within MS Access.
Thank you all for helping me.
look at the
SELECT *
FROM SYS.OBJECTS A
LEFT JOIN SYS.COLUMNS B ON A.OBJECT_ID = B.OBJECT_ID
WHERE A.TYPE_DESC = 'USER_TABLE'
and select your specific columns

Coldfusion server mapping to sql server

I have a ColdFusion server connected to MySQL database. Now I am changing the database to an existing MSSql server .. MSSql server has a similar database that of MySQL but the table names and column names are different. My question is that how can I map the new MSSql server to the ColdFusion server without changing the ColdFusion code.. Means without changing the table name and column names in ColdFusion code..
Thanks in advance
If the schemas are different (different column names and number of columns) then you probably have no choice but to refactor your CF code to reflect the new MSSQL schema. If there is a one to one relationship between the table and column names from one DB to the next you could use views - but it would make for a very confusing development environment. Again... each table would have to "match" for number of columns and types of data. Example
Old table "users"
firstname, lastname address
New table "tblUsers"
fname, lname, addr
Given the schemas above, you might have a query in your CF Code that looked like:
<cfquery name="getUsers" datasource="blah">
SELECT firstname, lastname, address
</cfquery>
So it would fail when you switched the DB. However, if you created a view like so:
CREATE VIEW [dbo].[Users]
AS
SELECT u.fname AS firstname,
u.lname AS lastname
u.addr AS address
FROM dbo.tblusers
Then your code would work. Again I am NOT recommending this. Your best course of action is to alter the schema to reflect your code or to refactor your code to work against the new schema. But technically it does answer your question :)
Unless you're already using ORM, here is no handy function or mapping mechanism in CF that would allow you to do this. There may be some manipulation at the driver level, or dipping into the java code that creates the sql strings to do text parsing there, but that's outside of my realm of expertise.
My guess, though, is that you have a lot of queries scattered throughout the application and are therefore daunted at the task of redoing all of them. Personally, I would refactor at least the data access of this app into one or more .cfc's. Even if all you do is wrap each query into a function call and replace the cfquery code with a function call, you're consolidating all of the database calls into one place and can change things much easier going forward.

SQL to ACCESS 2010

I imported my SQL information into Access. How can I create a table in Access, then join or link it to an existing table already in Access 2010.
I just use 'Access Data Projects' (ADP). This allows me to keep everything on the SQL Server side, and it allows me to write stored procedures (and bind them to forms, etc) without writing mountains of linked table / SQL passthrough code.
An easy way is to set up a UNION query. That will leave your two tables intact but join the data.
A JOIN query would merge the data into one of the existing tables.
http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins post has some good info about that.

How access data between databases in mysql?

I'm working in a project that is divided into multiple modules. Each module have it's own independent database in mysql, but now, the modules need to obtain data between them. For example we're going to develop a new "admin" module, and every other modules need to access the data in the "admin" database. I know that I can make a query like
select * from admin.table
to obtain data from other database, but each module (and the new "admin" module) are created in CakePHP. I think one possible solution is use something like Synonyms (like the ones in Oracle or SQL Server), but MySQL don't support it. Someone have a better idea? Thanks
I have a feeling CakePHP can handle cross-database relations. Try setting $useDbConfig for each model to a connection for the respective database. CakePHP should generate multiple queries (atleast one per database connection) and join the results together for you. This approach should work fine for simple relations, but there might not be full support for relations such as HABTM.
How about using views:
create view admin_table as select * from admin.table
Then, you just need to set $tableName to admin_table.
I may be wrong, but I think querying is based on
select * from database.owner.table ... and the implied owner would be the "dbo" (database owner). So, you MIGHT be able to do the following...
select a1., b1. from database1.table1 a1, database2.table2 b1 where a1.fld1 = b1.fld1 ...