Create Table and Alter table:

 

Hi All,

 I am using SQl server studio management to create table.

How to set two attributes as a primary key: composite key. like ( proj_id, emp id) both as primary key.

How to specify the forign key constraint. using alter table

Please give me the example: don't syntax which msdn gives.

 

Thanks and Regards

  Abdul M.G

0
abdulmg
8/31/2007 11:47:34 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
1054 Views

Similar Articles

[PageSpeed] 11
Get it on Google Play
Get it on Apple App Store

Hi,

Look at this.

 

1    CREATE TABLE Menu
2    (
3        MenuId int,
4        Title varchar(50),
5        Url varchar(256),
6        ParentId int NULL
7    )
8    
9    ALTER TABLE Menu ADD CONSTRAINT MenuId PRIMARY KEY 
10   
11   ALTER TABLE Menu ADD CONSTRAINT ParentId REFERENCES Menu(MenuId)
  
Zafar Iqbal
VP Technology
Hansvits


** Please mark as ANSWER if my reply helped you
0
ziqbalbh
8/31/2007 1:12:29 PM

Hi here is one more example:

 

CREATE TABLE Orders_2( OrderID int IDENTITY(1,1) NOT NULL,EmployeeID int NOT NULL,OrderDate datetime NULL DEFAULT(GETDATE()),Freight money NULL DEFAULT (0) CHECK(Freight >= 0),)GO--Creating Primary Key and a Reference. 

ALTER TABLE Orders_2 ADD CONSTRAINT pk_EID primary key(EmployeeID)

GO

ALTER TABLE Orders_2 ADD CONSTRAINT OrderID REFERENCES Orders_2(OrderID)

 

Regards,

Sandeep. 

 

Please mark as answer if it works for you.

0
krishnasandeep
7/30/2008 12:34:15 PM
Reply:

Similar Artilces:

Altering a proxy table created with CREATE EXISTING TABLE
Please take a look at the following suggestion: http://sqla.stackexchange.com/questions/720/altering-a-proxy-table-created-with-create-existing-table Thanks in advance! Volker Good suggestion Volker. We will consider it for a future release. Karim On 5/19/2010 9:23 AM, Volker Barth wrote: > Please take a look at the following suggestion: > > http://sqla.stackexchange.com/questions/720/altering-a-proxy-table-created-with-create-existing-table > > > > Thanks in advance! > > Volker ...

how to join existing table with table created by "create existing table"
"create existing table" can help to create a table which is linked to a sp select selection. but can this table be join to other physical tables? Yes, proxy tables can be used in joins. -bret ymho wrote: > "create existing table" can help to create a table which is > linked to a sp select selection. > but can this table be join to other physical tables? but i cant, pls refer my example below: create procedure po_t1 (@p1 char(8) ) as begin select ret_date=convert(datetime,@p1) end go CREATE EXISTING TABLE t1 (ret_out1 datetime not null, ...

alter table of table A causes trigger on table B accesseng table A to fail
hi, i recently faced a strange problem, i have two tables, table A and table B table A has a update trigger which updates data in table B. i altered table B to add two more columns. after which when i updated table A(modifying 1 row), my tran log got full. there was a threshold proc which got fired but it did'nt help much. i though the tables had been corrupted. ran dbcc tablealloc on syslogs, table A, table B, no errors. Just to be sure I ran a dbcc checkdb, checkalloc and checkcatalog - no errors i recreated the trigger - no use. dropped the trigger. updated the table it ...

Creating Table to Connect to a SQL Server Table
Hello everyone! I need to create some tables when my web page is been created these tables are in a SQL server database. I found a sample code to do that using a Access table can someone please send me or point me out to some link where I can learn how to do that. Tia Charles   -------------- Sample code I got from the net ----- private void buildGrid() { string sql; sql = "SELECT * FROM Products"; System.Data.OleDb.OleDbDataAdapter daSrc = new System.Data.OleDb.OleDbDataAdapter (sql, dbCon); DataTable oTable1 = new DataTable("Products"); daSrc.Fill(oTable1); sql = "S...

create table statement not creating table
This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C5515B.09D1B7E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Version ASA9.0.1 build 1964 I have a script that I apply to our databases to add tables, triggers, = stored procedures,... using dbisqlc. When I run the script on a particular database 3 tables are not getting = created properly. I am not seeing any errors in the isql.txt file = created by dbisqlc regarding the table create, but later when I try = adding triggers on the new tables I receiv...

Create table hangs but table was created
12.0.0.6 on Solaris. In a Java application, we create small tables on the fly "create table MyTable (id char(20) NOT NULL)". It's been there for quite a while. Then in the middle of one day, every time it hangs there. We then tried it on isql, same behavior. Then we found that even though the call didn't return, the table was actually created on the database. This lasted for about two hours. Then it went back to normal behavior. Could anyone think of what might have caused it? Thanks, Bill ...

grant alter table, drop table, truncate table
Granting Object Permissions I'm looking for a possibility to grant alter table, drop table and truncate table to a user or a group who is not the owner of that table. Also I don't want to give this user or group the sa or sso role. Does someone know a possible solution? Joerg Armbruster jarmbruster@quoka.com This is a multi-part message in MIME format. --------------858C4374005D95B10660EFB9 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Joerg, You can not grant these permissions to anyone other thanin the case of alter table ...

how to create a new sql table from xml table through coding
I have a xml tableProgramatically I have to convert the data to sql table and show the data in the grid view from the sql tableall I have to do by coding onlycan it be possible  Hi, As far as I know Torque can generate SQL source from an XML schema describing a database structure: http://db.apache.org/torque/releases/torque-3.1.1/generator/ However you need to do that throught coding which is not as simple as it sounds. You may have to transform xml schema to sql schema manually or use xslt. Or you can load xml schema into dataset and create database schema from dataset. Hop...

Create access table using sql table field
 hi friends , i need create mdb file with table and data , the data will come from sql server 2005 table , for example i have table employee table contain some fields like name mobile number and others ,, now i  need to create access mdb file with table and data , data is mobile numbers of employee(just only one field) ,  i m using ASP.net C# 2.0, plz help me yarTHANKS FOR ADVANCE     Hello Raghavendra,                          &nbs...

From Table to Table
I am working in Delphi 4 and ran into a roadblock I am unfamiliar with. I am trying to search and find values in one table based off of matching values in another. For example a table of objects with fields like name, description, type, ect; and a table of object properties in which each object can be represented multiple times based on the settings on the page at the time. So if i search the object property table (and eventually loop through to repeat for all objects) to find all cases of visible objects when a certain criteria is met. It stops on the first object with "Yes" in th...

Tables?! Why Tables?!
Bit random...but why does everything have to be rendered as a table?  It's starting to get quite annoying.  Formview - does this need to be a table?  the Menu??  Wouldn't it make sense to allow the option to...say...not render a Menu as a table?  Am I the only one that thinks this or are there others?  www.internetgeeks.co.ukwww.norwichbookclub.co.uk You can use CSS Adapters to create your own adapters to override how the controls render it self. In the next version of ASP.Net, you will probably have more flexibility to specify the surrounding elements of th...

chg of domain drops/creates table
Having rev.eng. an ASE 12.5 database to PD9, I'm structuring the PDM with new domains. However when modifying the DB, PD insists on 1) adding new domain 2) creating tmp-table 3) move data to tmp table, drop table 4) create new table, move data from tmp-table, drop tmp-table 5) recreating index, fk, whatever... Why on earth doesn't it just do an alter table? (ie: add new domain, alter table ) Sincerely, Peter Simonsen, PB veteran PD newbie This is the generalist approach. You can intelligently look at the base data type of the column and the new domain ...

Reverse Engineer created copies of table (table:1, table:2)... How do I merge them back into 1 table?
PowerDesigner 12.1 I just reverse-engineered about 20 tables from our database, and it took one of my key tables and created two copies ("TableName : 1" and "TableName : 2"). I'm sure the engine was trying to make the diagram easier for it to auto-layout, but I want all the FKs and such from one table). How do I merge them back into just one table? Thanks, Jason Jason Vogel wrote: > PowerDesigner 12.1 > > I just reverse-engineered about 20 tables from our database, and it took > one of my key tables and created two copies ("Tabl...

How to create SQL Tables from Random XML files and Upload its data to those tables
Hi,I was wondring if there is a way to automatically create SQL Tables when an XML file is uploaded and load its data to that SQL table? So here is what I was thinking:1- Create a xsd file from that XML2- Create the SQL Table from that xsd3- Upload the data to that table. Is this possible? I have done something like this before, but the colum data type is Variant which I don't want.             using Microsoft.SqlServer.Management.Common;            using M...

Web resources about - Create Table and Alter table: - asp.net.sql-datasource

iRobot Create - Wikipedia, the free encyclopedia
iRobot Create is a hobbyist robot manufactured by iRobot that is based on the Roomba platform and was introduced in 2007. However, iRobot Create ...

The Knot Creates Facebook Page To Help Hurricane Sandy Victims Salvage Their Weddings
The damage in the wake of Hurricane Sandy included some 2,300 weddings that had to be postponed or rescheduled, according to wedding portal The ...

How Emoji Intelligence Can Create Actionable Insights
... local social intelligence software provider Geofeedia , says emojis can also be used as a listening tool, for brands to take action and create ...

Create stunning black and white photos with Camera Noir
... text, email, or social media. Or, you can just save your beautiful picture to your device. Overall thoughts Camera Noir may have been created ...

MIT researchers create ‘untraceable’ text messaging that’s even more secure than Tor
... be as completely secure as many of us had assumed , we were intrigued to see that some researchers at MIT are now claiming that they've created ...

Singaporean students create device to help fight Parkinson's symptoms
Team PD Loggers, a group of students from the National University of Singapore, have invented a device that prevents falls resulting from a Parkinsonian ...

US report warns of ISIS' ability to create fake passports
New York Post US report warns of ISIS' ability to create fake passports CNN Washington (CNN) A new intelligence report shared with law enforcement ...

Can A Coupon Taste Good? Krispy Kreme Creates Barcode Of Glaze For Free Dozen Donut Coupon
... 12 free glazed dough tori from Krispy Kreme. To ensure everyone has their fair shot at what it’s calling #dayofthedozen, the company has created ...

Ky. Democrat Wants To Create A ‘Sanctuary State’ Exempt From EPA Rules
If cities can ignore immigration laws, why can't states ignore EPA rules?

EXCLUSIVE: Anne Geddes Gives Never-Before-Seen Look at How She Creates Her Famous Baby Calendars
EXCLUSIVE: Anne Geddes Gives Never-Before-Seen Look at How She Creates Her Famous Baby Calendars

Resources last updated: 12/12/2015 7:49:11 AM