I am working Sql Server 2005
My table name is Customer, the attributes are
Orderid
Customerid
Customeraddress
Wherein Customerid is the primary key and Orderid is the foreign key.
I want to know the
primary key name,
foreign key name and
the table name where the foreign key exists as a primary key
Is there any query to retrieve those names using a table name?
Kindly please provide me the queries...Thanks in advance
--list all columns in BLAH table
select c.name
from sys.columns c, sys.tables t
where c.object_id=t.object_id
and t.name='BLAH'
Related
I want to display image in report column. My table has composite primary key: ID and DATE.
When I add these columns in BLOB attributes as Primary Key Column 1 and Primary Key Column 2 report can not find data because of DATE column. Is it a problem in date format, or something else?
I'd suggest you to use only one column as a primary key column (a sequence or - if your database version supports it - an identity column).
Combination of [ID, DATE] you currently have can then be set to unique key (set both columns NOT NULL to "mimic" what primary key would do).
Why? Although your data model probably is just fine, certain Apex functionalities "suffer" from such things and prefer having a single-column primary keys.
I created triggers after creating a database in oracle apex. When testing in SQL code everything was fine, they worked. In the application I have the Professors table and when I change the value of the column "name", in the Courses table the value of the column "professor_name" should change. However when I change the value of the column "name" in the Professors table it throws me the error.
Here is the trigger definition:
CREATE OR REPLACE TRIGGER profesori_upd
AFTER UPDATE OF ime on profesori
FOR EACH ROW
BEGIN
UPDATE kursevi set ime_profesora = :new.ime
where pr_jmbg= :new.jmbg_pr;
END;
Here is the table Proffesors:
CREATE TABLE PROFESORI( jmbg_pr VARCHAR2(13) PRIMARY KEY,
ime VARCHAR2(20) NOT NULL,
prezime VARCHAR2(20) NOT NULL,
id_spreme NUMBER(5) NOT NULL,
CONSTRAINT profesor_sprema_fk FOREIGN KEY (id_spreme) REFERENCES
STRUCNE_SPREME(id)
);
Here is the table Courses:
CREATE TABLE KURSEVI(
opis VARCHAR2(40),
id_jezik NUMBER(10) NOT NULL,
id_nivo NUMBER(10) NOT NULL,
pr_jmbg VARCHAR2(13) NOT NULL,
CONSTRAINT kurs_jezik_fk FOREIGN KEY (id_jezik) REFERENCES JEZICI(id_j),
CONSTRAINT kurs_nivo_fk FOREIGN KEY (id_nivo) REFERENCES NIVOI_KURSEVA(id_n),
CONSTRAINT kurs_profesor_fk FOREIGN KEY (pr_jmbg) REFERENCES PROFESORI(jmbg_pr),
CONSTRAINT kurs_pk PRIMARY KEY(id_jezik,id_nivo,pr_jmbg)
);
After denormalization I added columns ime_profesora and prezime_profesora to the table Courses:
ALTER TABLE KURSEVI
ADD ime_profesora VARCHAR2(20);
ALTER TABLE KURSEVI
ADD prezime_profesora VARCHAR2(20);
UPDATE KURSEVI SET ime_profesora=( SELECT ime FROM PROFESORI WHERE profesori.jmbg_pr=kursevi.pr_jmbg);
UPDATE KURSEVI SET prezime_profesora=( SELECT prezime FROM PROFESORI WHERE profesori.jmbg_pr=kursevi.pr_jmbg);
ALTER TABLE KURSEVI
MODIFY ime_profesora varchar2(20) not null;
ALTER TABLE KURSEVI
MODIFY prezime_profesora varchar2(20) not null;
Error occurs after I try to change the value of the column name in the application, it does not say what the error is.
I have a table 'Person' with columns as 'Person_id as primary key','DOB' and 'place' as follows:
'Person'
Person_id |Name|DOB | place
Another table is "employee" where emp_id is primary key as follows:
'employee'
Person_id |emp_id|dateofjoin
And one more table "Details":
'Details'
emp_id|competency|rating
Now what i want is once i add the 'Person' table details the rest of the two tables as'employe' and 'Details' to get updated also with respect to the new Person added in the Person table. So, how can i have this using sql query? Also i want to clear that i am not very much familiar with database.
I think your after something like this ( for SQL Server ):
Create Procedure dbo.CreateMyEmployee ( #empName varchar(50),
#dob datetime,
#doj datetime,
#place as varchar(100),
#competency varchar(100),
#rating int)
As
Begin
Declare #empId int
Begin Transaction
Begin Try
Insert into Person (Name, DOB, Place)
Values ( #empName, #dob, #place)
Insert into employe (Name, dateofJoin) -- Assuming emp_id is identity columen
Values ( #empName, #doj)
Select #empId = SCOPE_IDENTITY()
Insert Into Details(emp_id, competency, rating)
Values (#empId, #competency, #rating)
Commit transaction
End Try
Begin Catch
Rollback Transaction
SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_MESSAGE() AS ErrorMessage
End Catch
End
I have a table named Products in which there is a column id. It has foreign key relationship with prtyID column in ProductTypes Table. I just want to change the column id of Products table to prtyID. How is it possible? Is there any doctrine command is available for that? Please help me to fix this..
I'm not sure what you are trying to do here... id should be the primary id of Products, not a foreign key for another table. Please add your code if you ask a question.
Usually, Doctrine will use the property name to create the table column. So changing the property name to $prtyId would change your table column as well.
You can give every column the attribute "name" in the annotation of your entity, which will change the column name in your database:
/**
* #ORM\Column(type="integer", name="prtyID")
**/
protected $id;
Or, because you don't define the foreign keys yourself in Doctrine but the association, you can define the association like this:
/**
* #ORM\ManyToOne(targetEntity="ProductTypes")
* #ORM\JoinColumn(name="prtyID", referencedColumnName="id")
*/
protected $type;
This will create the column "prtyID" in your products table which is defined as the foreign key to productTypes primary colum "id"
What is the meaning of "id=name" in the definition of the User entity?
Any resources about the persist field attributes?
User
name Text Asc id=name
The id=... attribute sets the column name for the tables primary key.
For Example:
Product id=product_id
name Text
quantityInStock Int
... will create a table with an integer primary key called "product_id"