SQL Server/T-SQL Tutorial/System Tables Views/sys.objects

Материал из SQL эксперт
Версия от 13:24, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Getting Details about User-Defined Functions in master

   <source lang="sql">

17> 18> SELECT 19> * 20> FROM 21> sysobjects 22> WHERE 23> type IN("FN", "TF") 24> AND 25> uid IN(user_id("system_function_schema"), 26> user_id("dbo")) 27> GO name

        id          xtype uid    info   status      base_schema_ver replinfo    parent_obj  crdate                  ftc

atid schema_ver stats_schema_ver type userstat sysstat indexdel refdate version deltrig instrig

    updtrig     seltrig     category    cache


----------- ----- ------ ------ ----------- --------------- ----------- ----------- ----------------------- ---
----------- ---------------- ---- -------- ------- -------- ----------------------- ----------- ----------- -------
----------- ----------- ----------- ------

linear_max

          318676233 FN         1      0           0               0           0           0 2007-10-22 04:26:43.660
  0           0                0 FN          0       0        0 2007-10-22 04:26:43.660           0           0
  0           0           0           0      0

fn_linear_max

          386152471 FN         1      0           0               0           0           0 2007-10-22 04:00:40.323
  0           0                0 FN          0       0        0 2007-10-22 04:00:40.323           0           0
  0           0           0           0      0

(2 rows affected) 1> 2></source>


Query sys.objects for object name

   <source lang="sql">

4> CREATE TABLE employee( 5> id INTEGER NOT NULL PRIMARY KEY, 6> first_name VARCHAR(10), 7> last_name VARCHAR(10), 8> salary DECIMAL(10,2), 9> start_Date DATETIME, 10> region VARCHAR(10), 11> city VARCHAR(20), 12> managerid INTEGER 13> ); 14> GO 1> INSERT INTO employee VALUES (1, "Jason" , "Martin", 5890,"2005-03-22","North","Vancouver",3); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (2, "Alison", "Mathews",4789,"2003-07-21","South","Utown",4); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (3, "James" , "Smith", 6678,"2001-12-01","North","Paris",5); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (4, "Celia" , "Rice", 5567,"2006-03-03","South","London",6); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (5, "Robert", "Black", 4467,"2004-07-02","East","Newton",7); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (6, "Linda" , "Green" , 6456,"2002-05-19","East","Calgary",8); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (7, "David" , "Larry", 5345,"2008-03-18","West","New York",9); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (8, "James" , "Cat", 4234,"2007-07-17","West","Regina",9); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (9, "Joan" , "Act", 6123,"2001-04-16","North","Toronto",10); 2> GO (1 rows affected) 1> 2> select * from employee; 3> GO id first_name last_name salary start_Date region city managerid


---------- ---------- ------------ ----------------------- ---------- -------------------- -----------
         1 Jason      Martin          5890.00 2005-03-22 00:00:00.000 North      Vancouver                      3
         2 Alison     Mathews         4789.00 2003-07-21 00:00:00.000 South      Utown                          4
         3 James      Smith           6678.00 2001-12-01 00:00:00.000 North      Paris                          5
         4 Celia      Rice            5567.00 2006-03-03 00:00:00.000 South      London                         6
         5 Robert     Black           4467.00 2004-07-02 00:00:00.000 East       Newton                         7
         6 Linda      Green           6456.00 2002-05-19 00:00:00.000 East       Calgary                        8
         7 David      Larry           5345.00 2008-03-18 00:00:00.000 West       New York                       9
         8 James      Cat             4234.00 2007-07-17 00:00:00.000 West       Regina                         9
         9 Joan       Act             6123.00 2001-04-16 00:00:00.000 North      Toronto                       10

(9 rows affected) 1> 2> select object_id, principal_id, type 3> from sys.objects 4> where name = "employee"; 5> 6> 7> drop table employee; 8> GO object_id principal_id type


------------ ----
1449772222         NULL U

(1 rows affected) 1> 2></source>


sys.objects catalog view contains a row for each object in the database.

   <source lang="sql">

5> 6> select top 10 * from sys.objects; 7> GO name object_id principal_id schema_id parent_object_id type type_desc

                                                create_date             modify_date             is_ms_shipped is_published is_schema_published

----------- ------------ ----------- ---------------- ---- ------------
----------------------- ----------------------- ------------- ------------ -------------------

sysrowsetcolumns 4 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.707 2005-10-14 01:36:06.707             1            0                   0

sysrowsets 5 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.690 2005-10-14 01:36:06.690             1            0                   0

sysallocunits 7 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.690 2005-10-14 01:36:06.690             1            0                   0

sysfiles1 8 NULL 4 0 S SYSTEM_TABLE

                                                2003-04-08 09:13:37.267 2003-04-08 09:13:37.267             1            0                   0

syshobtcolumns 13 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.707 2005-10-14 01:36:06.707             1            0                   0

syshobts 15 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.707 2005-10-14 01:36:06.707             1            0                   0

sysftinds 25 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.877 2005-10-14 01:36:06.877             1            0                   0

sysserefs 26 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.720 2005-10-14 01:36:06.720             1            0                   0

sysowners 27 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.863 2005-10-14 01:36:06.863             1            0                   0

sysdbreg 28 NULL 4 0 S SYSTEM_TABLE

                                                2005-10-14 01:36:06.737 2005-10-14 01:36:06.737             1            0                   0

(10 rows affected)</source>


sys.objects INNER JOIN sys.columns

   <source lang="sql">

4> CREATE TABLE employee( 5> id INTEGER NOT NULL PRIMARY KEY, 6> first_name VARCHAR(10), 7> last_name VARCHAR(10), 8> salary DECIMAL(10,2), 9> start_Date DATETIME, 10> region VARCHAR(10), 11> city VARCHAR(20), 12> managerid INTEGER 13> ); 14> GO 1> INSERT INTO employee VALUES (1, "Jason" , "Martin", 5890,"2005-03-22","North","Vancouver",3); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (2, "Alison", "Mathews",4789,"2003-07-21","South","Utown",4); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (3, "James" , "Smith", 6678,"2001-12-01","North","Paris",5); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (4, "Celia" , "Rice", 5567,"2006-03-03","South","London",6); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (5, "Robert", "Black", 4467,"2004-07-02","East","Newton",7); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (6, "Linda" , "Green" , 6456,"2002-05-19","East","Calgary",8); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (7, "David" , "Larry", 5345,"2008-03-18","West","New York",9); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (8, "James" , "Cat", 4234,"2007-07-17","West","Regina",9); 2> GO (1 rows affected) 1> INSERT INTO employee VALUES (9, "Joan" , "Act", 6123,"2001-04-16","North","Toronto",10); 2> GO (1 rows affected) 1> 2> select * from employee; 3> GO id first_name last_name salary start_Date region city managerid


---------- ---------- ------------ ----------------------- ---------- -------------------- -----------
         1 Jason      Martin          5890.00 2005-03-22 00:00:00.000 North      Vancouver                      3
         2 Alison     Mathews         4789.00 2003-07-21 00:00:00.000 South      Utown                          4
         3 James      Smith           6678.00 2001-12-01 00:00:00.000 North      Paris                          5
         4 Celia      Rice            5567.00 2006-03-03 00:00:00.000 South      London                         6
         5 Robert     Black           4467.00 2004-07-02 00:00:00.000 East       Newton                         7
         6 Linda      Green           6456.00 2002-05-19 00:00:00.000 East       Calgary                        8
         7 David      Larry           5345.00 2008-03-18 00:00:00.000 West       New York                       9
         8 James      Cat             4234.00 2007-07-17 00:00:00.000 West       Regina                         9
         9 Joan       Act             6123.00 2001-04-16 00:00:00.000 North      Toronto                       10

(9 rows affected) 1> 2> SELECT sys.objects. name 3> FROM sys.objects INNER JOIN sys.columns 4> ON sys.objects.object_id = sys.columns. object_id 5> WHERE sys.objects.type = "U" 6> AND sys. columns. name = "project_no"; 7> 8> 9> drop table employee; 10> GO name


(0 rows affected) 1></source>