Manish Sharma
Saturday 11 April 2015
Monday 16 June 2014
Wednesday 28 May 2014
Saturday 24 May 2014
Tuesday 20 May 2014
SQL tutorials 21: How To Rename Table in SQL using ALTER TABLE statement
Rename Table.
Rename table using SQL alter table statement Explained in Detail
Rename table using SQL alter table statement Explained in Detail
Sometimes we need to rename our table after we have already created it. In such cases there are two ways in which you can rename your table:
Drop the whole table altogether and recreate it with the new name. This is a logical choice if you are a student using your table for practice purposes only and can afford to lose the valuable data that your table contains. In practical environment there is a BIG NO for this method as Data held by database in tables is valuable and we cannot afford to lose it. If you opt for this method then for you I have a disclaimer –
“I do not recommend this method of renaming a table. If you opt this method then you will be responsible for your own loss.”
“I do not recommend this method of renaming a table. If you opt this method then you will be responsible for your own loss.”
Second way of renaming a table is by using ALTER TABLE data manipulation language (DDL) statement. This is the recommended way of renaming a table. Let’s see how.
To know how watch Video or You can read the full article here
Tuesday 13 May 2014
Saturday 26 April 2014
Oracle Database11g tutorials 17: SQL Primary Key constraint
You can read full detail article at my website
Primary key is an Input/output Data constraint. It serves the purpose of uniquely identifying the rows in a table
Technically Primary key constraint is the combination of NOT NULL and UNIQUE constraints.
Technically Primary key constraint is the combination of NOT NULL and UNIQUE constraints.
There are Two types of Primary key.
- Simple Primary key and
- Composite Primary Key.
Primary key which involves only one column of a table is called Simple Primary key whereas the primary key which involvesmore than one columns of a table is called Composite Primary key.
More than one column doesn't mean that you can give any number of columns. This still has some restrictions. A composite key in oracle can have maximum of 32 columns only.
More than one column doesn't mean that you can give any number of columns. This still has some restrictions. A composite key in oracle can have maximum of 32 columns only.
Primary key has a single function of identifying a unique row in the table. In case the simple primary key fails to identify that unique row, the user must then define a composite primary key.
You cannot Delete a Primary key if it is referenced by a foreign key in some other table. There is a unique index created automatically by Oracle so that the requirement of the uniqueness of the PRIMARY KEY constraint is fulfilled.
You cannot Delete a Primary key if it is referenced by a foreign key in some other table. There is a unique index created automatically by Oracle so that the requirement of the uniqueness of the PRIMARY KEY constraint is fulfilled.
There are few things which you should know about primary key. (Features of Primary key)
- A table can have only One Primary key no matter whether its Simple Primary Key Or Composite Primary Key.
- Columns which are participating in Primary Key cannot have NULL values. This means you cannot leave them unattended or you cannot put NULL value into them.
- As primary key is all about Row or Record’s uniqueness thus it will not allow duplicate values.
- When a Primary Key constraint has been defined on multiple columns then its values can be duplicated provided the duplication is happening within one single column. However the combination of values of all the columns defining each primary key constraint should be unique.
- Data-types such as LOB, LONG, LONG RAW, VARRAY, NESTED TABLE, BFILE, REF, TIMESTAMP WITH TIME ZONE, or user-defined type are not allowed with the columns which are part of Primary key. Any attempt of creating a primary key with the column of these data-types will raise SQL Error: ORA-02269.
- The size of the primary key cannot exceed approximately one database block.
- As I have already mentioned above that a composite primary key can have 32 columns maximum.
- The Primary key and Unique key should never be designated as the same column or combination of columns.
- You cannot specify a primary key when creating a sub view in an inheritance hierarchy. The primary key can be specified only for the top-level (root) view.
- Unique cluster Index gets created automatically on the time creating Primary key.
- Although it is not necessary for you to define a primary key yet it is always recommended to do so
Visit my website To read
How To define Primary Key using Create table and alter table statement, What is composite key, How to check constraint on table using data dictionaries, How to drop a constraint and How to enable or disable constraint.
Thanks
Subscribe to:
Posts (Atom)