I am new to SQLSERVER, so I am trying to learn from all these database views, in Oracle it use 'desc all_tables ' to database dictionary view, can some one tell me how to view SQLserver dictionary view like INFORMATION_SCHEMA.TABLES, or sys.tables?
IF I login as sa, but I only want to view the table list one schema at a time? how do I do that?
I tried :
select table_name from INFORMATION_SCHEMA.TABLES
where table_schema='CIT'....
select table_name from INFORMATION_SCHEMA.TABLES
where table_schema='CIT.DBO'.... give 0 result too.
it give me 0 result, but if I login as CIT, then
'select table_name from INFORMATION_SCHEMA.TABLES' will give 14 tables.
Plus, When I log into Query analyzer, all the tables has dbo. prefix. , why is that?
how do i return only the tables created by the user? in three of my databases i am inserting one record per 5 secs. in all the tables. how good is using triggers for 'insert instead of' for these tables?
I have a "master" table that holds the names of data tables (one record in the "master" table for each "data" table).
Can I create a ForeignKey constraint that will prevent the "master" table records from being removed if the cooresponding "data" table exists? Is the way to do this to use INFORMATION_SCHEMA.TABLES as the PrimaryKeyTable for the ForeignKey?
we've just installed SQL2005 and, as expected, are hitting problems with collation settings.
We have made sure that the collation of our new server is the same as the old (working) SQL2000 server (both are Latin1_General_CI_AS) but a function that works fine on the 2000 box just doesn't work on the 2005 box.
The problem is this...
Code Snippet select * from information_schema.[tables] as t left join :: fn_ListExtendedProperty('MS_Description','user','dbo','table',null,null,null) as xp on ( xp.objname = t.table_name )
...where that string comparison on "table_name" results in...
"Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "Latin1_General_CI_AI" in the equal to operation."
Now... I can't see where the "Latin1_General_CI_AI" is coming from. The two data sources are both "system" sources, so should, I would have thought, been the same. If I do...
execute sp_help "information_schema.tables"
...all the columns are Latin1_General_CI_AS. If I do...
execute sp_help fn_ListExtendedProperty
...the same collation is returned for all columns.
I've checked everything I can think of (server, master, tempdb, etc.), and everything seems to be "AS".
Where might this "AI" collation be defined ? We have only just installed 2005, so a re-install, while a pain, is not a massive problem, but what should we check/change ?
When the procedure : sp_tables is executed (master db), the table owners are either dbo or INFORMATION_SCHEMA, any detail about this last ? (to be precise, table_type is view and not table).
I need to change a column default to '' and not null for 1500 databases accross 10 servers.
if exists (select * from information_schema.columns where table_name = 'tblABC' and column_name = 'columnX' and data_type = 'VARCHAR' and is_nullable = 'No' and column_default = '('')' ) begin --do something to implement end
Here, there is a problem for and column_default = '('')' I have tried ''''+'('')' + '''' or "'('')'", neither works. Do you have any idea to deal with the ('') ?
I'm having a really hard time displaying the structure of my database using INFORMATION_SCHEMA. Can this be used with Access? I've used it before for sql databases but when I try it with this access one I get an error message telling me: Can't find file c:...INFORMATION_SCHEMA.mdb
I'm hoping maybe there's another command that works just as well or some other way to get around it.
I'm using Visual Web Developer 2005 Express and my .aspx pages are coded using VB so any insights would be awesome!
Hi I need to see all the indexes in a database. The ID has dbo rightsto the database, but not to the master. I can't see anything inINFORMATION_SCHEMA.CHECK_CONSTRAINTS orINFORMATION_SCHEMA.KEY_COLUMN_USAGEAn sa ID for the master sees everything however.Thanks for your helpPachydermitis
I'd like to get information about tables defined in the SqlCe20 database. So I tried to use the following which doesn't work:
string sql = "SELECT COLUMN_NAME AS CN FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?"cmd = new SqlCeCommand(sql, connection);cmd.Parameters.Add(newSqlCeDataParameter("A", DbTypes.NVarChar);cmd.Prepare();//later in codecmd.Parameters[0].Value = tableName;reader = cmd.ExecuteReader();while (reader.Read()).... Here the reader.Read() returns always false indepent of the table name. In contrast doing the following without parameter works as expected:
reader = cmd.ExecuteReader(string.Format("SELECT COLUMN_NAME AS CN FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{0}'", tableName)); while (reader.Read())
Because I have to execute this statemen often I have to use prepared statement with parameters.
Hiya, I'm trying to run reports, some of which have UserEntered as a criteria. So I'm filling up a list with (SELECT * FROM SysUsers WHERE IsLogin = 1), which is also pulling up INFORMATION_SCHEMA as a login. I'm not really sure why this would be an islogin = 1 or issqluser = 1. Is this a server default login,and if yes,why, and what can I do about it?
from SQL2005 information_schema, I don't see anything related to default constraint.
So, I still need the old way to use old stuff such as from sysobjects sobj inner join syscolumns scolumn. I need to check existing 3000 databases to drop any possible default for tableA.columnB's default and then add a new one.
I thought SQL2005 will stop let us to query system table to retrieve table structure info including default, but only via information_schema? :rolleyes: thanks David
Hi, I'm working with MSSQL2K+SP3a, Standard Edition. I defined linked server (MSDE). On the local server, I can do select * from [testDB].[INFORMATION_SCHEMA].[TABLES] -- local
select * from [testSRV].[testDB_far].[dbo].[sysobjects] -- linked
but not
select * from [testSRV].[testDB_far].[INFORMATION_SCHEMA].[TABLES]
How can I access the INFORMATION_SCHEMA on the linked server ?
Hi Folks:I'm a little new to SQLServer, so please pardon my ignorance!I've found the INFORMATION_SCHEMA views for TABLES, COLUMNS, andTABLE_CONSTRAINTS. I'm looking for the views that will give me the list ofcolumns by constraint.For instance, if Table1 has a unique key called Table1_UK01, I can find thatunder INFORMATION_SCHEMA.TABLE_CONSTRAINTS. But I also need to know thecolumns in that UK constraint. I've triedINFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE andINFORMATION_SCHEMA.KEY_COLUMN_USAGE, but the UK I have defined for this usertable doesn't seem to show up in either of those views.Can anyone point me in the right direction? Any sample queries would betremendously appreciated. I'm going to be using this meta-data toautomatically generate quite a bundle of stored procs that do updates basedon finding rows via unique keys...TIA,Dave
Hi I'm building a data warehouse - my end users connect using Access via ODBC Microsoft SQL Server driver (2000.85.1117.00).
However, whenever they connect using Access via ODBC they get a huge list of sys and INFORMATION_SCHEMA views, in addition to the data warehouse tables they need to access.
How can I remove these sys and INFORMATION_SCHEMA views from the list of tables/views presented to the end user?
I've tried denying access by changing permissions to deny in the public role of the master database - I have also changed permissions in the public role in the data warehouse database. When I do this, the ODBC connection fails to retrieve any objects because it doesn't have access to sys.databases (and various other unspecified objects). I'm stuck - help!
We have a legacy app where some of our web page urls were hardcoded into the stored procs (SQL 2000 SP4 database). We have changed the system and so changed the hardcoded strings with a value stored in a config table. We used the following query to identify the hardcoded urls (say LegacyPage.asp) €“
select routine_name from information_schema.routines where routine_definition like '%LegacyPage.asp?%'
However, even after this we keep getting issues with LegacyPage.asp being referenced. Tracing the code, I found that there is at least one SP (say spHardCoded) which does not turn up in the query, but does have the string LegacyPage.asp? in the routine definition. When I run the following query €“
select routine_name from information_schema.routines where routine_name = 'spHardCoded' and routine_definition like '%LegacyPage.asp?%'
0 rows are returned!
Am I missing something obvious here or is INFORMATION_SCHEMA.Routines metadata not always updated? Is there any way to force the metadata to be updated, before we query it? Is there a better system catalog view which lets me do the same thing? Any help would be really appreciated.
I have suddenly lost the ability to view the tables for one of my database via Enterprise Manager. It just sits at an hourglass and never returns! Alos, if I attempt to link to the tables via MSAccess's ODBC interface, I get a timeout.
I am able to view the table list for other user databases, as well as the system databases.
I am able to view other object list (like SPs) for the database in question, via Enterprise Manager.
I am able to perform a select query against the sysobjects table for the database in question.
Any ideas on why Enterprise Manager, and ODBC links, are hanging while trying to access the tables for one particular user database?
Any help is appreciated.
All other functions appear normal. If I can't figure anything out, or no one has any other ideas, I will try rebooting the server after the users are gone for the day.
Hi, I€™m new to sql ex 2005 and have a couple of questions I can€™t find the answers to. Q.1 I am working with VS web dev ex 2005 and I€™m trying to backup my db, is it as simple as copying the .mdf file? Or should I create a text file, or something else? Q.2 How do I view the content of the db in my web programs in the sql server 2005 ex? I can€™t figure out what to do, to view the content. I have tried to find tutorials on ex 05 but can€™t find answers to my questions. Help would be appreciated. Thank you.
I ran the following query in Query Analyzer for a 7 column table.SELECT c.name,c.colid FROM syscolumns c WHERE c.id=925962375 ORDER BYc.colidThe results were:I_CSD 1X_STE_XML2I_USR_LCK4T_CRT_RCD5I_USR_CRT_RCD6T_UDT_RCD7I_USR_UDT_RCD8If I use the information_schema view (SELECT column_name,ordinal_position FROM information_schema.columns WHERE table_name ='CSD_XML') I get the same results.The problem is that the colids go from 2 to 4 and the colids gothrough 8 when there are only 7 columns.At one time there was another column in the table, but it has sincebeen dropped and isn't there anymore. It seems that the colids insyscolumns did not update when the column was dropped.Is this because of the way I dropped the column? Is there anything Ican do now that it has happened?
I am trying to find the list of tables that make up any particular view in SQL server 2000. The information schema - VIEW_TABLE_USAGE would be the best tool, if only the sysdepends table worked! When I use the schema I get some but not all of my views. Has anyone got a solution, prefably one without cursors, that can identitfy the source tables for a view? I have used the following SQL, but unfortunately it gives too many results: SELECT VIEWS.name AS VIEW_NAME, TABLES.name AS TABLE_NAME, VIEW_SQL.text FROM sysobjects VIEWS INNER JOIN syscomments VIEW_SQL ON VIEWS.id = VIEW_SQL.id INNER JOIN sysobjects TABLES ON VIEW_SQL.text LIKE '%.' + TABLES.name + '%' WHERE (VIEWS.xtype = 'V') AND (TABLES.xtype = 'U') ORDER BY VIEWS.name, TABLES.name Justin
I would like to create a view that joins these tables. Each row show a product and all the qualities it has, from quality 1 to quality 8. If there is no N'th quality, to show blank/null/zero.
The problem is how to get values from multiple rows (in table Qualities) in a single row in the view.
Dear friends, is there any way to find the table names from a view?
ex: suppose i have a view named as vorganization.i need all the tables in this view. is it possible to get through a query? same case for procedures and functions also.........
Hi,I hope this is the right place to ask this question. If it is not,please let me know a more appropriate place.I have two tables.CREATE TABLE tblEmployees(EmployeeID int identity NOT NULL,LastName varchar(50) NULL,FirstName varchar(50) NULL,);CREATE TABLE tlkpDept(DeptID char(5) NULL,Name char(10) NULL,LongName char(50) NULL);Now I want to create a view called AssignedTo. [The application I'mdoing, will track the status of our customer requests. Each requestcan be assigned to either an individual employee or an entiredepartment]I want the view to have two columns, ID and LongName. ID should beeither the DeptID or the EmployeeID. The LongName column should beeither the LongName or the FirstName + LastName.I'm not even sure how to begin to write such a complex SQL.EnterpriseManager is being less than helpful too.Can anyone help?Thanks in advance.-Tom
I have about 14 tables that I am trying to tie together in a view tosee a user's status in our company.Joe User:Email - ActiveADP - ActivePortal - Inactiveetc.We need to track application access across the company, so we havetables for each application that contain user info(username,password(encrypted), start date, end date, changed date) so that wecan track who has what, and when they were given access as well aswhen it was taken away.Every application table has a userID attached to it.What I would like to do is to take the userID field and look for theirapplication access across the company. To do this, i'll have to lookfor the max value in each table because someone could be given access,have it taken away, and be given it again. People move all over theplace here, so we have to be able to track who has what, when, and atwhat building.I started out with trying to left outer join the tables together, butit didn't work. I tried doing something along the lines of:selectesarfAppEmail.emailID,esarfAppEmail.esarfUserID,CASE WHEN esarfAppEmail.endDate IS NULL Then 'Active' else 'Inactive'end as EmailStatus--,
If I have table1 and table2 with table2 having multiple rows tied to asingle row in table 1.What I am trying to do is set up a view that has one row that showsthe followingtable1.uniqueid, table1.name, table2.row1.detail, table2.row2.detail,table2.row3.detailI'd like to be able to do a select on the view and only come back withone row per widget. If possible, I'd actually like to be able toconcat all the rows from table 2 into one column if that's possible.table1.uniqueid, table1.name, (table2.row1.detail - table2.row2.detail- table2.row3.detail), table1.dateCreatedthxM@
We have created a view that selects from tables in two databases. it looks like something like this:
CREATE VIEW myview AS
SELECT col FROM db1.mytab
UNION SELECT col FROM db2.mytab;
Both tables have col as primary key.
When we executes SELECT col FROM myview WHERE col='SOMEVALUE' we receives the correct result but SQL server does not use any indexes. It performs a index scan on both tables. Wh and what can we do about it? The tables contains millions of rows so the performance is terrible.
The following works fine:
SELECT col FROM db1.mytab WHERE col ='SOMEVALUE'
UNION SELECT col FROM db2.mytab WHERE col ='SOMEVALUE';
I have a province table in a my database. I would like to link this province table to a resource table's Province_ID. This Province_ID is an int. Vic Valentic CEO/President Open Door 2 Elite Dr. #33 Hamilton, Ontario L8W 2N3 905-389-7492 http://www.wlu.ca/next/opendoor
PhoneType is an auxiliary table that has 5 records in it Home phone, Cell phone, Work phone, Pager, and Fax. Is there a way to do a join or maybe make a view of a view that would allow me to ultimately end up with…
StudnetID: 1 Name: John HomePhone: 123-456-7890 WorkPhone: 123-456-7890 CellPhone: Pager: 123-456-7890 Fax: Memo: This is one student record.
Some students will have no phone number, some will have all 5 most will have one or two. If possible I would like to do a setup like this in my database to keep from having to have null fields for 4 phone numbers that the majority of records won’t have. Thanks in advanced, Nathan Rover