How to add "Not for Replication" to identity column in powerdesigner model - powerdesigner

I am using Power designer version 15.3. I have designed a table in power designer model. In column properties I have checked Identity option for primarykey column.
Now I would like to add "Not for Replication" to this existing primarykey column in powerdesigner model.
What a option do I choose in power designer model to set a primarykey column to "Not for Replication" or how do I acheive the following Example SQL-script in power designer model?
Example SQL-script
CREATE TABLE HIST (
H_ID INT IDENTITY NOT FOR REPLICATION
)

I'm using PowerDesigner 16.5,
I hope in 15.3 this was already enabled
open your identity column properties dialog (in PDM)
go to "Microsoft" tab
check "Identity value not replicated"

Related

Identity column in view of SQL Server

I have a table in which has a Identity Column.
When I tried to create a view (with only this table), everything is still working fine, the ID property(which is used to mark auto increment number column) of Identity Column is still set to True
When there is only 1 table in view
Here is the diagram
But when I tried to create a view by join the mentioned above table with another table, the Identity Column is automatically set to false.
When I try to join 2 tables in view
Here is the diagram
This problem occurs maybe only in SQL Server 2016 (I tried with SQL Server 2008, it's still working fine)
Did anyone encounter similar problems? How to keep true value of Identity Column in View? Thanks

How to create identity column when importing data from Excel into MS SQL Server (with Import and Export Wizard)?

I need to import great amount of data from excel into MS SQL Server, using the Import/ Export Wizard. Then I'll continue importing more data into the same table on a weekly basis.
The bad thing is that my excel data doesn't have an identity column, which to use as a primary key. The only option with what available is to use 2 string columns as a primary key, which is not a good idea.
Is there a way the sql server to add auto-identity column (integer) when importing the data, and what's the trick? I prefer such a column to be automatically added, because I'll need to import big amount of data into the same table on a weekly basis.
I tested a couple of times (with no success) and looked for a solution in the internet, but didn't found an answer to that particular question. Thanks in advance!
You can create the table first along with the new identity column.
CREATE TABLE YourTable
(
id INT IDENTITY,
col1....
col2....
col3....
PRIMARY KEY(id)
)
Then run the import/export wizard. When you get to the destination section pick your newly created table and map all the fields except the identity column. After the import you can check the table and see the id column has been populated.
Column names in Excel sheet should be same as that of sql Table.
Map Excel columns with that of SQL table columns by Clicking Edit Mapping.
Just don't map that (identity) column of sql table to anything .
In Import-Export Wizard don't check Enable identity insert Checkbox. (Leave that
un selected).
and go ahead import .. This worked for me. !!!!!
Previously when i used to check Enable identity insert it used to give me error.
I had a similar issue. I have a SQL table with an identity column (auto increment ID value) defined. I needed to import an Excel spreadsheet into this table.
I finally got it to work via the following:
Do NOT add a column to the Excel spreadsheet for your identity column in the SQL table.
When you run the import wizard and get to the Edit Mappings step, do NOT select the Enable identity insert checkbox. This, in particular, was tripping me up.

How to get "Lookup" functionality in Access when linking to a SQL table?

I am building a SQL database which will have an Access 2010 front-end.
I would like some of the fields to be lookups in Access (ie the user clicks on the field in Access and a drop down populates). It is fairly straightforward to make a field a lookup for another table in Access but I can't seem to know how to do it in SQL and then propagate the changes.
My SQL knowledge is very basic. Here's an example of how I am creating my SQL tables:
CREATE TABLE RequestTypes (
RequestType varchar(50) PRIMARY KEY
);
INSERT INTO RequestTypes (RequestType) VALUES ('Val 1');
INSERT INTO RequestTypes (RequestType) VALUES ('Val 2');
INSERT INTO RequestTypes (RequestType) VALUES ('Val 3');
CREATE TABLE Projects (
ID int IDENTITY(1,1) PRIMARY KEY,
RequestStatus varchar(50) FOREIGN KEY REFERENCES RequestStatus(RequestStatus),
Quantity varchar(50)
);
I then connect to the database through the ODBC connection in Access.
How can I create my tables in SQL so that the RequestStatus field of my Projects table to have the same functionality a lookup table does? For example, being able to click on the RequestStatus attribute of a Project and select "Val 1" or "Val 2" or "Val 3" from a list. The above does require the tables to match but does not provide the "dropdown" lookup functionality.
Create the table in SQL Server, link to it, then use that table as the row source property for the desired combo box / drop down.
This is the very basic syntax to create a table in SQL Server:
CREATE TABLE LookupTest
(
ID INT NOT NULL,
LookupValue varchar(255)
);
When using datasheet view to SQL server, you cannot use a lookup.
However what you can do is create a continues form, and then simply drop in a combo box and use the wizard (or by hand) build the drop down and lookup you require. From the users point of view, they not really be able to discern the difference between editing data in that continues form as opposed to a continues form.
So the continues form will be based on the ONE table. The combo box column will be a long Number, and the combo box will have a row source of the table that provides the list of choices (the lookup values).
So you can build a screen like this:
Note how in above we have a continues form, but also some buttons etc. So a continues form is more flexible then a datasheet, but this “multiple items” forms result in much the same user interface.
Note how the first column is a combo box. In fact as above shows, you can drop in near any kind of control into these continues forms. The combo box can/will display a text column of your choice, but “behind” the scenes the combo box will store the PK id of the value you choose from the combo box into a single column in your forms table.
The result and look and feel is the same as a lookup column in an Access datasheet.
OPTION 1:
If you have linked the table to access, you can set the Lookup on the linked table. To do so, go to design view of the table. Select the field you want the Lookup against. Click on the Lookup tab. Choose Combo Box for the Display Control. In the Row Source specify the SQL. For example:
If I am on the CustomerName field I might want the following SQL:
SELECT DISTINCT Customer.CustomerName FROM Customer
OPTION 2:
I do not recommend handling it this way though. You are better off added a Combo Box to a form, setting the Row Source Type as "Table/Query" and the Row Source to the above query. lookup fields should be avoided in Access.

how to set auto increment column with sql developer

How do I set a column to increment automatically with Oracle SQL Developer? Why is the form disabled?
Note: The image shows the Data Modeler, but the question and top answer talk about editing an existing database.
If you want to make your PK auto increment, you need to set the ID column property for that primary key.
Right click on the table and select "Edit".
In "Edit" Table window, select "columns", and then select your PK
column.
Go to ID Column tab and select Column Sequence as Type. This will
create a trigger and a sequence, and associate the sequence to
primary key.
See the picture below for better understanding.
// My source is: http://techatplay.wordpress.com/2013/11/22/oracle-sql-developer-create-auto-incrementing-primary-key/
Unfortunately oracle doesnot support auto_increment like mysql does. You need to put a little extra effort to get that.
say this is your table -
CREATE TABLE MYTABLE (
ID NUMBER NOT NULL,
NAME VARCHAR2(100)
CONSTRAINT "PK1" PRIMARY KEY (ID)
);
You will need to create a sequence -
CREATE SEQUENCE S_MYTABLE
START WITH 1
INCREMENT BY 1
CACHE 10;
and a trigger -
CREATE OR REPLACE TRIGGER T_MYTABLE_ID
BEFORE INSERT
ON MYTABLE
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
if(:new.ID is null) then
SELECT S_MYTABLE.nextval
INTO :new.ID
FROM dual;
end if;
END;
/
ALTER TRIGGER "T_MYTABLE_ID" ENABLE;
You can make auto increment in SQL Modeler. In column properties window Click : General then Tick the box of Auto Increment. After that the auto increment window will be enabled for you.
UPDATE: In Oracle 12c onward we have an option to create auto increment field, its better than trigger and sequence.
Right click on the table and select "Edit".
In "Edit" Table window, select "columns", and then select your PK
column.
Go to Identity Column tab and select "Generated as Identity" as Type, put 1 in both start with and increment field. This will
make this column auto increment.
See the below image
From SQL Statement
IDENTITY column is now available on Oracle 12c:
create table t1 (
c1 NUMBER GENERATED by default on null as IDENTITY,
c2 VARCHAR2(10)
);
or specify starting and increment values, also preventing any insert into the identity column (GENERATED ALWAYS) (again, Oracle 12c+ only)
create table t1 (
c1 NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
c2 VARCHAR2(10)
);
EDIT : if you face any error like "ORA-30673: column to be modified is not an identity column", then you need to create new column and delete the old one.
#tom-studee you were right, it's possible to do it in the data modeler.
Double click your table, then go to the column section. Here double click on the column which will have the auto increment. In the general section there is a checkbox "autoincrement", just tick it.
After that you can also go to the "autoincrement" section to customize it.
When you save it and ask the data modeler to generate the SQL script, you will see the sequence and trigger which represent your autoincrement.
I found this post, which looks a bit old, but I figured I'd update everyone on my new findings.
I am using Oracle SQL Developer 4.0.2.15 on Windows.
Our database is Oracle 10g (version 10.2.0.1) running on Windows.
To make a column auto-increment in Oracle -
Open up the database connection in the Connections tab
Expand the Tables section, and right click the table that has the column you want to change to auto-increment, and select Edit...
Choose the Columns section, and select the column you want to auto-increment (Primary Key column)
Next, click the "Identity Column" section below the list of columns, and change type from None to "Column Sequence"
Leave the default settings (or change the names of the sequence and trigger if you'd prefer) and then click OK
Your id column (primary key) will now auto-increment, but the sequence will be starting at 1.
If you need to increment the id to a certain point, you'll have to run a few alter statements against the sequence.
This post has some more details and how to overcome this.
I found the solution here
Oracle doesn't have autoincrementing columns. You need a sequence and a trigger. Here's a random blog post that explains how to do it: http://www.lifeaftercoffee.com/2006/02/17/how-to-create-auto-increment-columns-in-oracle/
How to do it with Oracle SQL Developer:
In the Left pane, under the connections you will find "Sequences", right click and select create a new sequence from the context sensitive pop up. Fill out the details: Schema name, sequence_name, properties(start with value, min value, max value, increment value etc.) and click ok. Assuming that you have a table with a key that uses this auto_increment, while inserting in this table just give "your_sequence_name.nextval" in the field that utilizes this property.
I guess this should help! :)
Drag and drop your table from the left side menu into a worksheet and you will get a list of options. Pick "Insert" and then apply, and then done.

Make a varchar(50) column unique

I have a column (which represents an e-mail) in a SQL Server database with varchar(50) as data type and I would like to make it unique (do not allow the same two e-mail addresses). I cannot find a way to make such column unique in SQL Server Management Studio.
How to do that?
In T-SQL it would be
ALTER TABLE MyTable WITH CHECK
ADD CONSTRAINT UQ_MyTable_Email UNIQUE (EmailAddress)
Or as an explicit index
CREATE UNIQUE INDEX IXU_Email ON MyTable (EmailAddress)
Edit: I can't see how to create a constraint in the SSMS GUI: other answers show how to manage indexes. I do only use SQL though, never the GUI for this kind of work
In the Object Explorer under the table right-click the Indexes folder and choose New Index....
In the window that appears enter Index name:, tick the Unique checkbox and add your email field from the Add... button then click OK.
Try this:
ALTER TABLE [dbo].[TableName] ADD CONSTRAINT UNQ__TableName__ColumnName UNIQUE ([ColumnName])
From this:
http://msdn.microsoft.com/en-us/library/ms191166.aspx

Resources