I am more familiar with writing SQL for Oracle than MS SQL Server. Within Oracle there is a simple command, 'Describe', which actually shows the data types, and whether or not an attribute accepts NULLS. MS SQL Server does appear to support such a command, however I am looking for a way to describe the attributes of tables nonetheless.
Till recently we were using the following code to retreive schema information of columns of tables
Dim schemaTable = connection.GetOleDbSchemaTable( _ System.Data.OleDb.OleDbSchemaGuid.Columns, _ New Object() {Nothing, Nothing, tableName, Nothing})
Now instead of getting the name of table (which i was using as param for filtering) i'm going to receive a sql-query. Now my question is if I were to get a query like the following :
SO when i try to load from Master table to parent and child table i am using using expresssion like
select B.ID,A.* FROM FLATFILE_INVENTORY AS A JOIN DMS_INVENTORY AS B ON A.ACDealerID=B.DMSDEALERID AND A.StockNumber=B.STOCKNUMBER AND A.InventoryDate=B.INVENTORYDATE AND A.VehicleVIN=B.VEHICLEVIN WHERE convert(date,A.[FtpDate]) = convert(date,GETDATE()) and convert(date,B.Ftpdate) = convert(date,getdate()) ;
If i use this Expression i am getting the current system date data's only from Master table to parent and child tables.
My Problem is If i do this in my local sserver using the above Expression if i loaded today date and if need to load yesterday date i can change my system date to yesterday date and i can run this Expression.so that yeserday date data alone will get loaded from Master to parent and child tables.
If i run this expression to remote server i cannot change the system date in server.
while using this Expression for current date its loads perfectly but when i try to load yesterday data it takes current date date only not the yesterday date data.
What is the Expression on which ever date i am trying load in the master table same date need to loaded in Parent and child table without changing the system Date.
I'm using an ObjectDataSource in Visual Studio to retrieve records from a SQL Server 2005 database. I have a very simple dilemma. In a table I have fields FirstName, Surname, Address1, Address2, Address3 etc. None of these are mandatory fields. It is quite common for the user not to enter data in Address2, Address3, so the values are <null> in the SQL table. In Visual Studio 2005 I have an aspx form where users can pass search parameters to the ObjectDataSource and the results are returned according to the passed in parameters. The WHERE clause in my Table Adapter is:WHERE (Address1 LIKE @Address1 + '%') AND (Address2 LIKE @Address2 + '%') AND (Address3 LIKE @Address3 + '%') AND (FirstName LIKE @FirstName + '%') AND (Surname LIKE @Surname + '%') If, for example, I simply want to search WHERE FirstName LIKE ‘R’, this does not return any results if the value of Address3 is <null> My query is this: Could someone please show me the best way in Visual Studio 2005 to return records even if one of the Address fields is <null>. For reference, I have tried: Address3 LIKE @Address3 + '%' OR IS NULLThis does work, however itsimply returns every instance where Address3 is <null> (accounting for about 95% of the records in the database). Thanks in advance Simon
I’ve got a situation where the columns in a table we’re grabbing from a source database keep changing as we need more information from that database. As new columns are added to the source table, I would like to dynamically look for those new columns and add them to our local database’s schema if new ones exist. We’re dropping and creating our target db table each time right now based on a pre-defined known schema, but what we really want is to drop and recreate it based on a dynamic schema, and then import all of the records from the source table to ours.It looks like a starting point might be EXEC sp_columns_rowset 'tablename' and then creating some kind of dynamic SQL statement based on that. However, I'm hoping someone might have a resource that already handles this that they might be able to steer me towards.Sincerely, Bryan Ax
we have a table in our ERP database and we copy data from this table into another "stage" table on a nightly basis. is there a way to dynamically alter the schema of the stage table when the source table's structure is changed? in other words, if a new column is added to the source table, i would like to add the column to the stage table during the nightly refresh.
I'd like to create a temporary table with the same schema as an exiting table. How can I do this without hard coding the column definitions into the temporary table definition?
I'd like to do something like:
CREATE TABLE #tempTable LIKE anotherTable
..instead of...
CREATE TABLE #tempTable (id INT PRIMARY KEY, created DATETIME NULL etc...
I want to do something similar to ExecuteScalar in ADO.net but instead in T-SQL.Basically I want to do a query that will return the first value in the table queried and put it into a variable. How do I do this?Thanks in advance.
I am trying t get output for the following querry but I know am missing something. Can anyone help me out with it.
select distinct productnum, (SELECT SUM(quantity) FROM orderlineitem w WHERE w.productnum = e.productnum) as Quantity from orderlineitem e where parentOrderlineitemid is null order by Quantity desc)
In the above query am getting the productnum and quanity and it looks like this
productnum quantity abc 6 ttt 3 sss 1
What am tring to do to this query is that . From another table 'product' i want all the data to be retrieved with this productnum(the table 'product' has a column called prductnum). I don't know how to write a query for this.
my query is select * from product where productnum in ( select distinct productnum, (SELECT SUM(quantity) FROM orderlineitem w WHERE w.productnum = e.productnum) as Quantity from orderlineitem e where parentOrderlineitemid is null order by Quantity desc)
here is my table: MVPTABLE columnName: Accsno JanMail JanVisit JanPhone JanComments FebMail..upto DecMail DecVisit DecPhone DecComments.
eg: table with values: Accsno JanMail JanVisit JanPhone JanComments FebMAil FebVisit A234 1 2 3 yes jim 0 2 A234 0 2 0 No Comments 1 2 As34 0 0 0 No Comments 1 2 A235 1 2 3 yes jim 0 2 A235 0 2 0 No Comments 1 2 As35 0 0 0 No Comments 1 2
am sending 2 parameter as 1> @param1= A234 2> @param2= 'JanMail,JanVisit,JanPhone,FebMail,FebVisit,FebPhone,MarMail,MarVisit,MarPhone,AprMail,AprVisit,AprPhone,MayMail,MayVisit,MayPhone,JunMail,JunVisit,JunPhone,JulyMail,JulyVisit,JulyPhone,AugMail,AugVisit,AugPhone,SepMail,SepVisit,SepPhone,OctMail,OctVisit,OctPhone,NovMail,NovVisit,NovPhone,DecMail,DecVisit,DecPhone
based on these 2 parameter i wanted to retrieve respective Comments say, if @param1 Ac234 @param2= JanMail,JanVisit,JanPhone,MarMail if the value of JanMail or FebMAil....DecMail = 1,then retieve respective comments if the value of JanVisit,FebVisit..........DecVisit=2,then retrieve respective comments if the value of JanPhone,or FebPhone,.....DecPhone=3 then retive respective comments
I come from a MySQL background and have been having some trouble finding the MSSQL command that corresponds to MySQL's "describe." I Googled for around 1/2 hour but can't seem to find it.
I'd like it to simply use the schema of an already existing table (plus an additional column).
Is there a way to do this without having to manually write the table schema?
A simple example is:
I have a table OriginalTable (idCol, NameCol, InfoCol)
I'd like to create a temp instance of that table called tempTable which would have a final schema of
tempTable (idCol, NameCol, InfoCol, myTempCol)
The reason I'd like to do this using the schema is so that I don't need to update all my procedures in the future when we decide to add some more detail to the originaltable which needs to be selected as well.
Thanks a lot for any help or direction you can provide. -Ashleigh
I have a group of TV listing data need to map into database tables.Data looks like following:http://www.oniva.com/upload/1356/crew.jpgI want to create a table for productionCrew of each TV programthe data is like -crew -programID -member-member-member ... etc-programID -member-member-member ... etc-programID -member-member-member ... etc... etcabove are data from productionCrew of all TV program, for eachprogramID we have a list of members.Should I merge all member into a big string?Or should I use 2 tables to store the Crew data?If i use 2 tables, how the fields / column will look like?
Hi, how can i retrieve 10 fake rows from any table? for examle for a row it will seem like that.. Id Name Value Status----- ----------- ----------- ---------------1 null null null thanks in advance..
I'm writing a trigger for my DotNetNuke portal that requires me to read the value of a just inserted record. I believe I'm doing this right, still I'm unable to retrieve the desired value from the Inserted table. What am I doing wrong? Here is my code:
CREATE TRIGGER tr_addEditorRole ON [dbo].[UserPortals] AFTER INSERT AS Declare @Portal int set @Portal = (select PortalId FROM inserted)
Declare @TabId Int set @Tabid = (select TabID from Tabs where Tabs.PortalID = @Portal and Tabs.TabName = 'MyTab')
Declare @ModuleId int set @ModuleId = (SELECT ModuleId FROM Modules WHERE Modules.TabID = @TabId and Modules.ModuleTitle = 'MyModule')
I am having a big problem, trying to create datebase. I have 3 tables: SUPERAVATAR, MASTERAVATAR, MEGAAVATAR. - SuperAvatars are heroes in an online role playing gaming. They have an ID, ‘superavatarID’ which contain an UNIQUE NUMBER NOT NULL PRIMARY KEY to identify them. A wisdom – ‘trickster’,’conjuror’,’magician’, etc.. A current owner… who is the user or player of the game and has that Super Avatar– we associate the link to USERID to know the person. SuperAvatars can be fathers or mothers of Mega Avatars. -MegaAvatars are the children of SuperAvatars…. They also have an ID UNIQUE NUMBER NOT NULL PRIMARY KEY to indentify them. A magic power – it can be a ‘Leader’ or ‘Sheep’… A ‘parent’ – parent is the number identifying to know to who Super Avatar belongs. e.g. SUPERAVAT WISD CURRENTOWNER FATHEROF MOTHEROF 1 Thick 3 1 2 Mentally Ch. 11 3 3 Smart 9 2 4 Genius 16 4 5 Thick 19
-We see that MEGAAVATAR 1 has a magic power as Magician and his father is ‘1’. ‘1’ identifies the SUPERAVATAR. We see SUPERAVATARID…. who has the number ‘1’? the first in the row… who has wisdom – thick and he belongs to the USER with ID number 3. -We see MEGAAVATARID… we choose the number 2…. His magic power is as WIZARD… and his father is the number 3. We see SUPERAVATARID now… we look up the SuperavatarID 3…. We can see he has a wisdom – GENIUS… who belongs to the USERID 16 and he is father of MEGAAVATAR number 2. The list can carry on and never stop.
I have this Problems: We create in this example 3 tables: Users, SuperAvatar, MegaAvatar
SQL CREATE TABLE users(userID NUMBER CONSTRAINT pk_user PRIMARY KEY,email VARCHAR2(50) NOT NULL UNIQUE,password VARCHAR2(15) NOT NULL UNIQUE,subscription CHAR(8) NOT NULL CHECK (subscription IN('ACTIVE' , 'INACTIVE' ) ) );
CREATE TABLE superavatar(superavatarID NUMBER CONSTRAINT pk_superavatar PRIMARY KEY, wisdom VARCHAR2(19) NOT NULL CHECK (wisdom IN ('THICK', 'MENTALLY CHALLENGED', 'AWAKE', 'SMART', 'GENIUS')), currentOwner NUMBER NOT NULL, fatherOf NUMBER,motherOf NUMBER);
CREATE TABLE megaavatar (megaavatarID NUMBER CONSTRAINT pk_megaavatar PRIMARY KEY, magicPower VARCHAR2(12) NOT NULL CHECK (magicPower IN('TRICKSTER','CONJUROR','MAGICIAN','WIZARD','SORCERER')), parent NUMBER);
Now, the 3 tables are created….. What happen when we try to insert values to this table? In this case we insert to User Table some examples: INSERT INTO users VALUES('3','john@hotmail.com','great78','ACTIVE'); INSERT INTO users VALUES('9','chrisandsandra@gmail.com','chrisandra)','ACTIVE'); Now, we insert to SuperAvatar some examples; INSERT INTO superavatar VALUES('1','THICK','3','1',''); INSERT INTO superavatar VALUES('3','SMART','9','3',''); | | ‘9’ is the UserID that we already insert to the User table What’s the problem? We have to insert manually the data from USERID to CURRENTOWNER as we didn’t match or link CURRENTOWNER from SUPERAVATAR Table to USERID from USER Table with a SQL CODE. What happen if we have thousands of USERS that they register to this game…? We will never know to how belongs that SUPERAVATAR but if someone do it manually can spend a year.
I am trying to fix this problem …. I add in SUPERAVATAR TABLE ‘CHECK’ in currentOwner..
SQL> CREATE TABLE superavatar (superavatarID NUMBER CONSTRAINT pk_superavatar PRIMARY KEY, wisdom VARCHAR2(19) NOT NULL CHECK (wisdom IN ('THICK', 'MENTALLY CHALLENGED', 'AWAKE', 'SMART', 'GENIUS')), currentOwner NUMBER NOT NULL CHECK (currentOwner IN(SELECT userID FROM users)), fatherOf NUMBER, motherOf NUMBER); * ERROR: ORA-02251: subquery not allowed here
Hi! I needto find the last record that has been inserted on a table. If I perform a SELCT * FROM mytable , will I receive the data based on the inserted order (natural order)? In that case i'll simply need to check the last record of the results I got in my application to find the last inserted one? (no I am not looking for an identity number ^^)
There is a table with a single column with 75 rows - 50 unique / 25duplicates. How would pull back a list of the rows that have/areduplicates?This is a question that I got in an interview. I didn't get it,obviously....Thanks,Tim
I have a problem, in one of my db's I have a table tblpersons in schema web the rest of the table's in the db are in schema dbo. Now I removed the user web, but I want to change the schema of tblpersons from web.tblpersons to dbo.tblpersons. I created a stored procedure with the line " ALTER SCHEMA dbo TRANSFER web.tblpersons", when executing this I get an error that the table tblpersons couldn't be found.
Hi all, i m using sql server2005 CTP...i created a database called TEL and in that database i created a user(in security) as USE [TEL] GO /****** Object: User [COLL_DB] Script Date: 09/27/2005 15:38:51 ******/ GO CREATE USER [COLL_DB] FOR LOGIN [loginName] WITH DEFAULT_SCHEMA=[COLL_DB]
Now,when i m trying to create a table in the database TEL as CREATE TABLE [COLL_DB].abc (c numeric) commit;
it gives me error saying The specified schema name "COLL_DB" either does not exist or you do not have permission to use it.
Now,can someone tell me...what i have to do to fix this error????????? thanks...
We currently have all tables in the dbo schema, but for organizational reason we would like to split them up in multiple schemas and I wonder if that can be done without re-creating the tables.
So my question is, is there a way to move a table into a different schema without re-creating it? (For those familiar with Postgres I'm looking for an equivalent to "ALTER TABLE foo SET SCHEMA newschema") sp_rename only allows a "one-part name" for the new name, so apparently that cannot be used.
I have created a table on SQL Server from SAS. The table gets created fine. However, the table schema has my user ID in it (AD-ENTmyuserid.Table1). How can I change the schema to dbo.(dbo.Table1)? It's fine if I have to make this change in SQL Server Management Studio.
I am a bit confused and wish to share this with you for help. We are designing a billing application to bill telephone calls. It currently handles a single rate plan. So what it does is that it looks up the RATES table and matches the called number area code with the RATES.ACCESS_Code field to find the tariff for that area and multiplies that by the number of minutes. Here is the current schema.
CALLS •ID (pkid) •Called Number •Duration
RATES •Destination Name •Access_Code (pkid) •Tariff
Now the problem is that we need to process calls based on RATES per OPERATOR. Each operator is a telephony carrier with similar RATES. However, each call will be prefixed with a number to indicate which operator carried that call. Accordingly, the database should relate that prefix with the proper operator and then looks up the RATES that are related to that operator.
In conclusion we will have a replica of the RATES table for multiple operators. An operator is only supposed to have two fields I guess (name and ID).
So now we need to re-engineer the schema to adapt to this situation.
Eg. 95004433313445 (Will be identified as BT operator) 93004422376234 (Will be identified as AT&T operator)
I created a schema, Admin. I have to transfer a table from the dbo schema to the admin schema. I keep getting an error that I do not have permission or the table does not exist.
Simply looking for confirmation here - is my syntax correct?
ALTER SCHEMA Admin TRANSFER MyShop.Addresses; (MyShop is the Database, Addresses is the table)
NOTE: When I created the schema, I did not create an inner table. The syntax for that was simply CREATE SCHEMA Admin;