My BSOOC need a query table primary key foreign key information of SQL, last night research to 1 o'clock in the morning, finally can achieve this goal:
Oracle:
Select O.obj# as ObjectId, o.name as TableName, oc.name as ConstraintName,
Decode (c.type#, 1, ' C ', 2, ' P ', 3, ' U ',
4, ' R ', 5, ' V ', 6, ' O ', 7, ' C ', '? ') As ConstraintType,
Col.name as Column
. major_id and F. minor_id = 0 where D. Name = 'query table name'
II,-- Query stored proceduresSelect case. xtype when 'p' then' Stored Procedure 'end as lx,. name, B. text from sysobjects a left Outer Join syscomments B on. id = B. ID where xtype = 'P'-- Query viewSelect case. xtype when 'v'then' view 'end as lx,. name, B. text from sysobjects a left Outer Join syscomments B on. id = B. ID where xtype = 'V'
-- Primary
I summarize the 3 kinds:1. According to the front desk to obtain the WID number to the background to the activity of foreign key table data back, get wname;2. Add the property public string Wname{get;set in the Entity Class primary key table model, and join Model.wname to return the display when the BLL business logic is acquired at the front end;3. Inline query
Label: Introduction This article mainly introduces the method to avoid inserting duplicate values when inserting data into a table, mainly involves Ignore,on DUPLICATE key update,replace, and then we will take a look at the three ways to deal with them separately. IGNORE Use Ignore to automatically ignore duplicate record rows when the inserted value encounters a primary
· What is a database?The warehouse where the data is stored.· What is the difference between a database and a data structure?To solve the problem of manipulating data in memory, the database should solve the problem of manipulating data in the hard disk. Data structures study some abstract data models (ADT) and some of the operations defined on the model, the database is composed of tables, relationships, operations.· What is a primary
Label: Ar data sp c as BS Text R OptimizationPrimary Key: primary key constraintUnique key: unique key constraintSimilarities: Unique, neither value nor repetitionDifferences:1. A table can have only one primary
Unique Constraint
The unique constraint is basically the same as creating a unique index, because when creating a unique constraint, the system creates a unique index and implements the constraint through the unique index. However, the unique constraint intuitively expresses the uniqueness of the corresponding column so that the purpose of the corresponding index is clearer. Therefore, we generally recommend that you create a unique constraint instead of only creating a unique index.
Create a
--Delete foreign keys
Syntax: ALTER TABLE name DROP constraint foreign KEY constraint name
Such as:
ALTER TABLE STU_PKFK_SC DROP constraint fk_s
ALTER TABLE STU_PKFK_SC DROP constraint Fk_c
--Adding foreign keys
Syntax: ALTER TABLE name ADD constraint foreign KEY constraint name foreign key (column name) references Reference foreign
1, the creation of the primary keyMethod One: Declare the field PRIMARY KEY constraint directly in the SQL statementCREATE TABLE table_name (ID type[length] constraint pk_name primary key,name tyoe[length],age type[length],class_id);Method two: Alter change table ADD constra
In my BSOOC, I need an SQL statement to query the foreign key information of the table's primary key. Last night I studied it at AM and finally achieved this goal:Oracle:Select o. obj # as objectId, o. name AS tableName, oc. name AS constraintName,Decode (c. type #, 1, 'C', 2, 'P', 3, 'u ',4, 'R', 5, 'V', 6, 'O'
", which is Base64 encoded in the middle.This filters out other parts except Base64, decoding Base64 to get the binary contents of the public key.Here the binary encoding format is as follows:First 11 bytes Fixed0 0 0 7 ' s ' s ' h '-' R ' s ' a 'Immediately following 4 bytes is an int value representing the byte length of the public exponentThe conversion can be achieved by means of a shift character and addition or BigInteger.After the length is obtained, the length byte is read from the next
1, add a new field for the currently existing tableALTER TABLE student add studentname varchar (a) not null;2, set the primary key self-increment for the fields in the currently existing tableALTER TABLE student add constraint Pk_studentid PrimaryKey (StudentID);3, set a foreign key for the field in the currently existing tableALTER TABLE student ADD constraint f
Label:After the two tables have been built, build the association1. Right-click the table you want to associate, select design2. Select the column name you want to associate, right-click, select Relationship3, the following dialog box appears, click on the bottom left of the Add key, select the right table and column to return the anti-strike ellipsis selection4, in the bottom dialog box, the primary
I. query basic table information
SelectUTC. column_name, UTC. data_type, UTC. data_length, UTC. data_precision,UTC. data_scale, UTC. nullable, UTC. data_default, UCC. CommentsFromUser_tab_columns UTC, user_col_comments UCCWhereUTC. table_name = UCC. table_nameAnd UTC. column_name = UCC. column_nameAnd UTC. table_name = 'onlinexls'OrderColumn_id
Note: order by column_id indicates that the result is displayed in the order of data structure design.
Ii. query the table's
Primary key and foreign keyPrimary key: Is an index, help us quickly find, in the database to take out a column as the primary key, data is the only non-repeatable data can not be empty data, slowing down the new dataRight-click Table, point design, right-click column, set a
Label:First, SQL constraints Constraints are used to restrict the type of data being added to the tag You can specify the constraint (via the CREATE TABLE statement) when creating the table, or after the table is created (via the ALTER table statement) The following constraints are mainly discussed: 1) Not NULL 2) UNIQUE 3) PRIMARY KEY 4) FOREIGN KEY 5) CHECK 6
Tags: query sort no--strong blog cannot str mys body
DefinedPrimary Key-uniquely identifies a record, cannot be duplicated, is not allowed to be emptyForeign key--the foreign key of the table is the primary key of another table, the foreign
Constraint (Constraint): A restriction on the column properties, fields of the created table. such as: Not Null/unique/primary key/foreign Key/checkScope of Action:① column-level constraints only work on one column② table-level constraints can function on multiple columns (of course, table-level constraints can also work on a column)Defined by: The column constra
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.